go.uber.org/cadence@v1.2.9/client/client.go (about) 1 // Copyright (c) 2017 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 // Package client contains functions to create Cadence clients used to communicate to Cadence service. 22 // 23 // Use these to perform CRUD on domains and start or query workflow executions. 24 package client 25 26 import ( 27 "context" 28 "errors" 29 30 "go.uber.org/cadence" 31 "go.uber.org/cadence/.gen/go/cadence/workflowserviceclient" 32 s "go.uber.org/cadence/.gen/go/shared" 33 "go.uber.org/cadence/encoded" 34 "go.uber.org/cadence/internal" 35 "go.uber.org/cadence/workflow" 36 ) 37 38 const ( 39 // QueryTypeStackTrace is the build in query type for Client.QueryWorkflow() call. Use this query type to get the call 40 // stack of the workflow. The result will be a string encoded in the encoded.Value. 41 QueryTypeStackTrace string = internal.QueryTypeStackTrace 42 43 // QueryTypeOpenSessions is the build in query type for Client.QueryWorkflow() call. Use this query type to get all open 44 // sessions in the workflow. The result will be a list of SessionInfo encoded in the encoded.Value. 45 QueryTypeOpenSessions string = internal.QueryTypeOpenSessions 46 47 // QueryTypeQueryTypes is the build in query type for Client.QueryWorkflow() call. Use this query type to list 48 // all query types of the workflow. The result will be a string encoded in the EncodedValue. 49 QueryTypeQueryTypes string = internal.QueryTypeQueryTypes 50 ) 51 52 type ( 53 // Options are optional parameters for Client creation. 54 Options = internal.ClientOptions 55 56 // FeatureFlags define which breaking changes can be enabled for client 57 FeatureFlags = internal.FeatureFlags 58 59 // StartWorkflowOptions configuration parameters for starting a workflow execution. 60 StartWorkflowOptions = internal.StartWorkflowOptions 61 62 // HistoryEventIterator is a iterator which can return history events 63 HistoryEventIterator = internal.HistoryEventIterator 64 65 // WorkflowRun represents a started non child workflow 66 WorkflowRun = internal.WorkflowRun 67 68 // WorkflowIDReusePolicy defines workflow ID reuse behavior. 69 WorkflowIDReusePolicy = internal.WorkflowIDReusePolicy 70 71 // QueryWorkflowWithOptionsRequest defines the request to QueryWorkflowWithOptions 72 QueryWorkflowWithOptionsRequest = internal.QueryWorkflowWithOptionsRequest 73 74 // QueryWorkflowWithOptionsResponse defines the response to QueryWorkflowWithOptions 75 QueryWorkflowWithOptionsResponse = internal.QueryWorkflowWithOptionsResponse 76 77 // ParentClosePolicy defines the behavior performed on a child workflow when its parent is closed 78 ParentClosePolicy = internal.ParentClosePolicy 79 80 // CancelOption values are functional options for the CancelWorkflow method. 81 // Supported values can be created with: 82 // - WithCancelReason(...) 83 CancelOption = internal.Option 84 85 // Client is the client for starting and getting information about a workflow executions as well as 86 // completing activities asynchronously. 87 Client interface { 88 // StartWorkflow starts a workflow execution 89 // The user can use this to start using a function or workflow type name. 90 // Either by 91 // StartWorkflow(ctx, options, "workflowTypeName", arg1, arg2, arg3) 92 // or 93 // StartWorkflow(ctx, options, workflowExecuteFn, arg1, arg2, arg3) 94 // The errors it can return: 95 // - EntityNotExistsError, if domain does not exists 96 // - BadRequestError 97 // - WorkflowExecutionAlreadyStartedError 98 // - InternalServiceError 99 StartWorkflow(ctx context.Context, options StartWorkflowOptions, workflowFunc interface{}, args ...interface{}) (*workflow.Execution, error) 100 101 // ExecuteWorkflow starts a workflow execution and return a WorkflowRun instance and error 102 // The user can use this to start using a function or workflow type name. 103 // Either by 104 // ExecuteWorkflow(ctx, options, "workflowTypeName", arg1, arg2, arg3) 105 // or 106 // ExecuteWorkflow(ctx, options, workflowExecuteFn, arg1, arg2, arg3) 107 // The errors it can return: 108 // - EntityNotExistsError, if domain does not exists 109 // - BadRequestError 110 // - InternalServiceError 111 // 112 // WorkflowRun has 2 methods: 113 // - GetRunID() string: which return the first started workflow run ID (please see below) 114 // - Get(ctx context.Context, valuePtr interface{}) error: which will fill the workflow 115 // execution result to valuePtr, if workflow execution is a success, or return corresponding 116 // error. This is a blocking API. 117 // NOTE: if the started workflow return ContinueAsNewError during the workflow execution, the 118 // return result of GetRunID() will be the started workflow run ID, not the new run ID caused by ContinueAsNewError, 119 // however, Get(ctx context.Context, valuePtr interface{}) will return result from the run which did not return ContinueAsNewError. 120 // Say ExecuteWorkflow started a workflow, in its first run, has run ID "run ID 1", and returned ContinueAsNewError, 121 // the second run has run ID "run ID 2" and return some result other than ContinueAsNewError: 122 // GetRunID() will always return "run ID 1" and Get(ctx context.Context, valuePtr interface{}) will return the result of second run. 123 // NOTE: DO NOT USE THIS API INSIDE A WORKFLOW, USE workflow.ExecuteChildWorkflow instead 124 ExecuteWorkflow(ctx context.Context, options StartWorkflowOptions, workflow interface{}, args ...interface{}) (WorkflowRun, error) 125 126 // GetWorkflow retrieves a workflow execution and return a WorkflowRun instance (described above) 127 // - workflow ID of the workflow. 128 // - runID can be default(empty string). if empty string then it will pick the last running execution of that workflow ID. 129 // 130 // WorkflowRun has 2 methods: 131 // - GetRunID() string: which return the first started workflow run ID (please see below) 132 // - Get(ctx context.Context, valuePtr interface{}) error: which will fill the workflow 133 // execution result to valuePtr, if workflow execution is a success, or return corresponding 134 // error. This is a blocking API. 135 // If workflow not found, the Get() will return EntityNotExistsError. 136 // NOTE: if the started workflow return ContinueAsNewError during the workflow execution, the 137 // return result of GetRunID() will be the started workflow run ID, not the new run ID caused by ContinueAsNewError, 138 // however, Get(ctx context.Context, valuePtr interface{}) will return result from the run which did not return ContinueAsNewError. 139 // Say ExecuteWorkflow started a workflow, in its first run, has run ID "run ID 1", and returned ContinueAsNewError, 140 // the second run has run ID "run ID 2" and return some result other than ContinueAsNewError: 141 // GetRunID() will always return "run ID 1" and Get(ctx context.Context, valuePtr interface{}) will return the result of second run. 142 GetWorkflow(ctx context.Context, workflowID string, runID string) WorkflowRun 143 144 // SignalWorkflow sends a signals to a workflow in execution 145 // - workflow ID of the workflow. 146 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID. 147 // - signalName name to identify the signal. 148 // - arg is the data (or nil) to send with the signal, which can be read with the signal channel's Receive out-arg. 149 // The errors it can return: 150 // - EntityNotExistsError 151 // - InternalServiceError 152 // - WorkflowExecutionAlreadyCompletedError 153 SignalWorkflow(ctx context.Context, workflowID string, runID string, signalName string, arg interface{}) error 154 155 // SignalWithStartWorkflow sends a signal to a running workflow. 156 // If the workflow is not running or not found, it starts the workflow and then sends the signal in transaction. 157 // - workflowID, signalName, signalArg are same as SignalWorkflow's parameters 158 // - options, workflow, workflowArgs are same as StartWorkflow's parameters 159 // The errors it can return: 160 // - EntityNotExistsError, if domain does not exist 161 // - BadRequestError 162 // - InternalServiceError 163 SignalWithStartWorkflow(ctx context.Context, workflowID string, signalName string, signalArg interface{}, 164 options StartWorkflowOptions, workflowFunc interface{}, workflowArgs ...interface{}) (*workflow.Execution, error) 165 166 // CancelWorkflow cancels a workflow in execution 167 // - workflow ID of the workflow. 168 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID. 169 // The errors it can return: 170 // - EntityNotExistsError 171 // - BadRequestError 172 // - InternalServiceError 173 // - WorkflowExecutionAlreadyCompletedError 174 CancelWorkflow(ctx context.Context, workflowID string, runID string, opts ...CancelOption) error 175 176 // TerminateWorkflow terminates a workflow execution. 177 // workflowID is required, other parameters are optional. 178 // - workflow ID of the workflow. 179 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID. 180 // The errors it can return: 181 // - EntityNotExistsError 182 // - BadRequestError 183 // - InternalServiceError 184 // - WorkflowExecutionAlreadyCompletedError 185 TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details []byte) error 186 187 // GetWorkflowHistory gets history events of a particular workflow 188 // - workflow ID of the workflow. 189 // - runID can be default(empty string). if empty string then it will pick the last running execution of that workflow ID. 190 // - whether use long poll for tracking new events: when the workflow is running, there can be new events generated during iteration 191 // of HistoryEventIterator, if isLongPoll == true, then iterator will do long poll, tracking new history event, i.e. the iteration 192 // will not be finished until workflow is finished; if isLongPoll == false, then iterator will only return current history events. 193 // - whether return all history events or just the last event, which contains the workflow execution end result 194 // Example:- 195 // To iterate all events, 196 // iter := GetWorkflowHistory(ctx, workflowID, runID, isLongPoll, filterType) 197 // events := []*shared.HistoryEvent{} 198 // for iter.HasNext() { 199 // event, err := iter.Next() 200 // if err != nil { 201 // return err 202 // } 203 // events = append(events, event) 204 // } 205 GetWorkflowHistory(ctx context.Context, workflowID string, runID string, isLongPoll bool, filterType s.HistoryEventFilterType) HistoryEventIterator 206 207 // CompleteActivity reports activity completed. 208 // activity Execute method can return activity.ErrResultPending to 209 // indicate the activity is not completed when it's Execute method returns. In that case, this CompleteActivity() method 210 // should be called when that activity is completed with the actual result and error. If err is nil, activity task 211 // completed event will be reported; if err is CanceledError, activity task cancelled event will be reported; otherwise, 212 // activity task failed event will be reported. 213 // An activity implementation should use GetActivityInfo(ctx).TaskToken function to get task token to use for completion. 214 // Example:- 215 // To complete with a result. 216 // CompleteActivity(token, "Done", nil) 217 // To fail the activity with an error. 218 // CompleteActivity(token, nil, cadence.NewCustomError("reason", details) 219 // The activity can fail with below errors ErrorWithDetails, TimeoutError, CanceledError. 220 CompleteActivity(ctx context.Context, taskToken []byte, result interface{}, err error) error 221 222 // CompleteActivityByID reports activity completed. 223 // Similar to CompleteActivity, but may save cadence user from keeping taskToken info. 224 // activity Execute method can return activity.ErrResultPending to 225 // indicate the activity is not completed when it's Execute method returns. In that case, this CompleteActivityById() method 226 // should be called when that activity is completed with the actual result and error. If err is nil, activity task 227 // completed event will be reported; if err is CanceledError, activity task cancelled event will be reported; otherwise, 228 // activity task failed event will be reported. 229 // An activity implementation should use activityID provided in ActivityOption to use for completion. 230 // domain name, workflowID, activityID are required, runID is optional. 231 // The errors it can return: 232 // - ErrorWithDetails 233 // - TimeoutError 234 // - CanceledError 235 CompleteActivityByID(ctx context.Context, domain, workflowID, runID, activityID string, result interface{}, err error) error 236 237 // RecordActivityHeartbeat records heartbeat for an activity. 238 // taskToken - is the value of the binary "TaskToken" field of the "ActivityInfo" struct retrieved inside the activity. 239 // details - is the progress you want to record along with heart beat for this activity. 240 // The errors it can return: 241 // - EntityNotExistsError 242 // - InternalServiceError 243 RecordActivityHeartbeat(ctx context.Context, taskToken []byte, details ...interface{}) error 244 245 // RecordActivityHeartbeatByID records heartbeat for an activity. 246 // details - is the progress you want to record along with heart beat for this activity. 247 // The errors it can return: 248 // - EntityNotExistsError 249 // - InternalServiceError 250 RecordActivityHeartbeatByID(ctx context.Context, domain, workflowID, runID, activityID string, details ...interface{}) error 251 252 // ListClosedWorkflow gets closed workflow executions based on request filters. 253 // Retrieved workflow executions are sorted by start time in descending order. 254 // (Retrieved workflow executions could also be sorted by closed time in descending order, 255 // if cadence server side config EnableReadFromClosedExecutionV2 is set to true.) 256 // Note: heavy usage of this API may cause huge persistence pressure. 257 // The errors it can return: 258 // - BadRequestError 259 // - InternalServiceError 260 // - EntityNotExistError 261 ListClosedWorkflow(ctx context.Context, request *s.ListClosedWorkflowExecutionsRequest) (*s.ListClosedWorkflowExecutionsResponse, error) 262 263 // ListOpenWorkflow gets open workflow executions based on request filters. 264 // Retrieved workflow executions are sorted by start time in descending order. 265 // Note: heavy usage of this API may cause huge persistence pressure. 266 // The errors it can return: 267 // - BadRequestError 268 // - InternalServiceError 269 // - EntityNotExistError 270 ListOpenWorkflow(ctx context.Context, request *s.ListOpenWorkflowExecutionsRequest) (*s.ListOpenWorkflowExecutionsResponse, error) 271 272 // ListWorkflow gets workflow executions based on query. This API only works with ElasticSearch, 273 // and will return BadRequestError when using Cassandra or MySQL. The query is basically the SQL WHERE clause, 274 // examples: 275 // - "(WorkflowID = 'wid1' or (WorkflowType = 'type2' and WorkflowID = 'wid2'))". 276 // - "CloseTime between '2019-08-27T15:04:05+00:00' and '2019-08-28T15:04:05+00:00'". 277 // - to list only open workflow use "CloseTime = missing" 278 // Retrieved workflow executions are sorted by StartTime in descending order when list open workflow, 279 // and sorted by CloseTime in descending order for other queries. 280 // The errors it can return: 281 // - BadRequestError 282 // - InternalServiceError 283 ListWorkflow(ctx context.Context, request *s.ListWorkflowExecutionsRequest) (*s.ListWorkflowExecutionsResponse, error) 284 285 // ListArchivedWorkflow gets archived workflow executions based on query. This API will return BadRequest if Cadence 286 // cluster or target domain is not configured for visibility archival or read is not enabled. The query is basically the SQL WHERE clause. 287 // However, different visibility archivers have different limitations on the query. Please check the documentation of the visibility archiver used 288 // by your domain to see what kind of queries are accept and whether retrieved workflow executions are ordered or not. 289 // The errors it can return: 290 // - BadRequestError 291 // - InternalServiceError 292 ListArchivedWorkflow(ctx context.Context, request *s.ListArchivedWorkflowExecutionsRequest) (*s.ListArchivedWorkflowExecutionsResponse, error) 293 294 // ScanWorkflow gets workflow executions based on query. This API only works with ElasticSearch, 295 // and will return BadRequestError when using Cassandra or MySQL. The query is basically the SQL WHERE clause 296 // (see ListWorkflow for query examples). 297 // ScanWorkflow should be used when retrieving large amount of workflows and order is not needed. 298 // It will use more ElasticSearch resources than ListWorkflow, but will be several times faster 299 // when retrieving millions of workflows. 300 // The errors it can return: 301 // - BadRequestError 302 // - InternalServiceError 303 ScanWorkflow(ctx context.Context, request *s.ListWorkflowExecutionsRequest) (*s.ListWorkflowExecutionsResponse, error) 304 305 // CountWorkflow gets number of workflow executions based on query. This API only works with ElasticSearch, 306 // and will return BadRequestError when using Cassandra or MySQL. The query is basically the SQL WHERE clause 307 // (see ListWorkflow for query examples). 308 // The errors it can return: 309 // - BadRequestError 310 // - InternalServiceError 311 CountWorkflow(ctx context.Context, request *s.CountWorkflowExecutionsRequest) (*s.CountWorkflowExecutionsResponse, error) 312 313 // GetSearchAttributes returns valid search attributes keys and value types. 314 // The search attributes can be used in query of List/Scan/Count APIs. Adding new search attributes requires cadence server 315 // to update dynamic config ValidSearchAttributes. 316 GetSearchAttributes(ctx context.Context) (*s.GetSearchAttributesResponse, error) 317 318 // QueryWorkflow queries a given workflow's last execution and returns the query result synchronously. Parameter workflowID 319 // and queryType are required, other parameters are optional. The workflowID and runID (optional) identify the 320 // target workflow execution that this query will be send to. If runID is not specified (empty string), server will 321 // use the currently running execution of that workflowID. The queryType specifies the type of query you want to 322 // run. By default, cadence supports "__stack_trace" as a standard query type, which will return string value 323 // representing the call stack of the target workflow. The target workflow could also setup different query handler 324 // to handle custom query types. 325 // See comments at workflow.SetQueryHandler(ctx Context, queryType string, handler interface{}) for more details 326 // on how to setup query handler within the target workflow. 327 // - workflowID is required. 328 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID. 329 // - queryType is the type of the query. 330 // - args... are the optional query parameters, which will be sent to your query handler function's args. 331 // The errors it can return: 332 // - BadRequestError 333 // - InternalServiceError 334 // - EntityNotExistError 335 // - QueryFailError 336 QueryWorkflow(ctx context.Context, workflowID string, runID string, queryType string, args ...interface{}) (encoded.Value, error) 337 338 // QueryWorkflowWithOptions queries a given workflow execution and returns the query result synchronously. 339 // See QueryWorkflowWithOptionsRequest and QueryWorkflowWithOptionsResponse for more information. 340 // The errors it can return: 341 // - BadRequestError 342 // - InternalServiceError 343 // - EntityNotExistError 344 // - QueryFailError 345 QueryWorkflowWithOptions(ctx context.Context, request *QueryWorkflowWithOptionsRequest) (*QueryWorkflowWithOptionsResponse, error) 346 347 // ResetWorkflow reset a given workflow execution and returns a new execution 348 // See ResetWorkflowRequest and ResetWorkflowResponse for more information. 349 // The errors it can return: 350 // - BadRequestError 351 // - InternalServiceError 352 // - EntityNotExistError 353 ResetWorkflow(ctx context.Context, request *s.ResetWorkflowExecutionRequest) (*s.ResetWorkflowExecutionResponse, error) 354 355 // DescribeWorkflowExecution returns information about the specified workflow execution. 356 // - runID can be default(empty string). if empty string then it will pick the last running execution of that workflow ID. 357 // 358 // The errors it can return: 359 // - BadRequestError 360 // - InternalServiceError 361 // - EntityNotExistError 362 DescribeWorkflowExecution(ctx context.Context, workflowID, runID string) (*s.DescribeWorkflowExecutionResponse, error) 363 364 // DescribeTaskList returns information about the target tasklist, right now this API returns the 365 // pollers which polled this tasklist in last few minutes. 366 // The errors it can return: 367 // - BadRequestError 368 // - InternalServiceError 369 // - EntityNotExistError 370 DescribeTaskList(ctx context.Context, tasklist string, tasklistType s.TaskListType) (*s.DescribeTaskListResponse, error) 371 372 // RefreshWorkflowTasks refreshes all the tasks of a given workflow. 373 // - workflow ID of the workflow. 374 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID. 375 // The errors it can return: 376 // - BadRequestError 377 // - DomainNotActiveError 378 // - ServiceBusyError 379 // - EntityNotExistError 380 RefreshWorkflowTasks(ctx context.Context, workflowID, runID string) error 381 } 382 383 // DomainClient is the client for managing operations on the domain. 384 // CLI, tools, ... can use this layer to manager operations on domain. 385 DomainClient interface { 386 // Register a domain with cadence server 387 // The errors it can throw: 388 // - DomainAlreadyExistsError 389 // - BadRequestError 390 // - InternalServiceError 391 Register(ctx context.Context, request *s.RegisterDomainRequest) error 392 393 // Describe a domain. The domain has 3 part of information 394 // DomainInfo - Which has Name, Status, Description, Owner Email 395 // DomainConfiguration - Configuration like Workflow Execution Retention Period In Days, Whether to emit metrics. 396 // ReplicationConfiguration - replication config like clusters and active cluster name 397 // The errors it can throw: 398 // - EntityNotExistsError 399 // - BadRequestError 400 // - InternalServiceError 401 Describe(ctx context.Context, name string) (*s.DescribeDomainResponse, error) 402 403 // Update a domain. 404 // The errors it can throw: 405 // - EntityNotExistsError 406 // - BadRequestError 407 // - InternalServiceError 408 Update(ctx context.Context, request *s.UpdateDomainRequest) error 409 } 410 ) 411 412 const ( 413 // WorkflowIDReusePolicyAllowDuplicateFailedOnly allow start a workflow execution 414 // when workflow not running, and the last execution close state is in 415 // [terminated, cancelled, timeout, failed]. 416 WorkflowIDReusePolicyAllowDuplicateFailedOnly WorkflowIDReusePolicy = internal.WorkflowIDReusePolicyAllowDuplicateFailedOnly 417 418 // WorkflowIDReusePolicyAllowDuplicate allow start a workflow execution using 419 // the same workflow ID,when workflow not running. 420 WorkflowIDReusePolicyAllowDuplicate WorkflowIDReusePolicy = internal.WorkflowIDReusePolicyAllowDuplicate 421 422 // WorkflowIDReusePolicyRejectDuplicate do not allow start a workflow execution using the same workflow ID at all 423 WorkflowIDReusePolicyRejectDuplicate WorkflowIDReusePolicy = internal.WorkflowIDReusePolicyRejectDuplicate 424 425 // WorkflowIDReusePolicyTerminateIfRunning terminate current running workflow using the same workflow ID if exist, 426 // then start a new run in one transaction 427 WorkflowIDReusePolicyTerminateIfRunning = internal.WorkflowIDReusePolicyTerminateIfRunning 428 ) 429 430 const ( 431 // ParentClosePolicyTerminate means terminating the child workflow 432 ParentClosePolicyTerminate = internal.ParentClosePolicyTerminate 433 // ParentClosePolicyRequestCancel means requesting cancellation on the child workflow 434 ParentClosePolicyRequestCancel = internal.ParentClosePolicyRequestCancel 435 // ParentClosePolicyAbandon means not doing anything on the child workflow 436 ParentClosePolicyAbandon = internal.ParentClosePolicyAbandon 437 ) 438 439 // NewClient creates an instance of a workflow client 440 func NewClient(service workflowserviceclient.Interface, domain string, options *Options) Client { 441 return internal.NewClient(service, domain, options) 442 } 443 444 // NewDomainClient creates an instance of a domain client, to manage lifecycle of domains. 445 func NewDomainClient(service workflowserviceclient.Interface, options *Options) DomainClient { 446 return internal.NewDomainClient(service, options) 447 } 448 449 // make sure if new methods are added to internal.Client they are also added to public Client. 450 var _ Client = internal.Client(nil) 451 var _ internal.Client = Client(nil) 452 var _ DomainClient = internal.DomainClient(nil) 453 var _ internal.DomainClient = DomainClient(nil) 454 455 // NewValue creates a new encoded.Value which can be used to decode binary data returned by Cadence. For example: 456 // User had Activity.RecordHeartbeat(ctx, "my-heartbeat") and then got response from calling Client.DescribeWorkflowExecution. 457 // The response contains binary field PendingActivityInfo.HeartbeatDetails, 458 // which can be decoded by using: 459 // 460 // var result string // This need to be same type as the one passed to RecordHeartbeat 461 // NewValue(data).Get(&result) 462 func NewValue(data []byte) encoded.Value { 463 return internal.NewValue(data) 464 } 465 466 // NewValues creates a new encoded.Values which can be used to decode binary data returned by Cadence. For example: 467 // User had Activity.RecordHeartbeat(ctx, "my-heartbeat", 123) and then got response from calling Client.DescribeWorkflowExecution. 468 // The response contains binary field PendingActivityInfo.HeartbeatDetails, 469 // which can be decoded by using: 470 // 471 // var result1 string 472 // var result2 int // These need to be same type as those arguments passed to RecordHeartbeat 473 // NewValues(data).Get(&result1, &result2) 474 func NewValues(data []byte) encoded.Values { 475 return internal.NewValues(data) 476 } 477 478 // IsWorkflowError returns true if an error is a known returned-by-the-workflow error type, when it comes from 479 // WorkflowRun from either Client.ExecuteWorkflow or Client.GetWorkflow. If it returns false, the error comes from 480 // some other source, e.g. RPC request failures or bad arguments. 481 // Using it on errors from any other source is currently undefined. 482 // 483 // This checks for known types via errors.As, so it will check recursively if it encounters wrapped errors. 484 // Note that this is different than the various `cadence.Is[Type]Error` checks, which do not unwrap. 485 // 486 // Currently the complete list of errors checked is: 487 // *cadence.CustomError, *cadence.CanceledError, *workflow.ContinueAsNewError, 488 // *workflow.GenericError, *workflow.TimeoutError, *workflow.TerminatedError, 489 // *workflow.PanicError, *workflow.UnknownExternalWorkflowExecutionError 490 // 491 // See documentation for each error type for details. 492 func IsWorkflowError(err error) bool { 493 var custom *cadence.CustomError 494 if errors.As(err, &custom) { 495 return true 496 } 497 var cancel *cadence.CanceledError 498 if errors.As(err, &cancel) { 499 return true 500 } 501 502 var generic *workflow.GenericError 503 if errors.As(err, &generic) { 504 return true 505 } 506 var timeout *workflow.TimeoutError 507 if errors.As(err, &timeout) { 508 return true 509 } 510 var terminate *workflow.TerminatedError 511 if errors.As(err, &terminate) { 512 return true 513 } 514 var panicked *workflow.PanicError 515 if errors.As(err, &panicked) { 516 return true 517 } 518 var can *workflow.ContinueAsNewError 519 if errors.As(err, &can) { 520 return true 521 } 522 var unknown *workflow.UnknownExternalWorkflowExecutionError 523 if errors.As(err, &unknown) { 524 return true 525 } 526 return false 527 } 528 529 // WithCancelReason can be passed to Client.CancelWorkflow to provide an explicit cancellation reason, 530 // which will be recorded in the cancellation event in the workflow's history, similar to termination reasons. 531 // This is purely informational, and does not influence Cadence behavior at all. 532 func WithCancelReason(reason string) CancelOption { 533 return internal.WithCancelReason(reason) 534 }