@temporalio/core-bridge 0.16.4 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/Cargo.lock +339 -226
  2. package/Cargo.toml +7 -3
  3. package/common.js +50 -0
  4. package/index.d.ts +7 -0
  5. package/index.js +12 -0
  6. package/package.json +7 -4
  7. package/releases/aarch64-apple-darwin/index.node +0 -0
  8. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  9. package/{index.node → releases/index.node} +0 -0
  10. package/releases/x86_64-apple-darwin/index.node +0 -0
  11. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  12. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  13. package/scripts/build.js +10 -50
  14. package/sdk-core/.buildkite/docker/Dockerfile +1 -1
  15. package/sdk-core/.buildkite/docker/docker-compose.yaml +2 -2
  16. package/sdk-core/.buildkite/pipeline.yml +2 -0
  17. package/sdk-core/Cargo.toml +1 -88
  18. package/sdk-core/README.md +30 -6
  19. package/sdk-core/bridge-ffi/Cargo.toml +24 -0
  20. package/sdk-core/bridge-ffi/LICENSE.txt +23 -0
  21. package/sdk-core/bridge-ffi/build.rs +25 -0
  22. package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +216 -0
  23. package/sdk-core/bridge-ffi/src/lib.rs +829 -0
  24. package/sdk-core/bridge-ffi/src/wrappers.rs +193 -0
  25. package/sdk-core/client/Cargo.toml +32 -0
  26. package/sdk-core/{src/pollers/gateway.rs → client/src/lib.rs} +101 -195
  27. package/sdk-core/client/src/metrics.rs +89 -0
  28. package/sdk-core/client/src/mocks.rs +167 -0
  29. package/sdk-core/{src/pollers → client/src}/retry.rs +172 -14
  30. package/sdk-core/core/Cargo.toml +96 -0
  31. package/sdk-core/{src → core/src}/core_tests/activity_tasks.rs +193 -37
  32. package/sdk-core/{src → core/src}/core_tests/child_workflows.rs +14 -14
  33. package/sdk-core/{src → core/src}/core_tests/determinism.rs +8 -8
  34. package/sdk-core/core/src/core_tests/local_activities.rs +328 -0
  35. package/sdk-core/{src → core/src}/core_tests/mod.rs +6 -9
  36. package/sdk-core/{src → core/src}/core_tests/queries.rs +54 -54
  37. package/sdk-core/{src → core/src}/core_tests/replay_flag.rs +8 -12
  38. package/sdk-core/{src → core/src}/core_tests/workers.rs +120 -33
  39. package/sdk-core/{src → core/src}/core_tests/workflow_cancels.rs +16 -26
  40. package/sdk-core/{src → core/src}/core_tests/workflow_tasks.rs +280 -292
  41. package/sdk-core/core/src/lib.rs +374 -0
  42. package/sdk-core/{src → core/src}/log_export.rs +3 -27
  43. package/sdk-core/core/src/pending_activations.rs +162 -0
  44. package/sdk-core/{src → core/src}/pollers/mod.rs +4 -22
  45. package/sdk-core/{src → core/src}/pollers/poll_buffer.rs +1 -1
  46. package/sdk-core/core/src/protosext/mod.rs +396 -0
  47. package/sdk-core/core/src/replay/mod.rs +210 -0
  48. package/sdk-core/core/src/retry_logic.rs +144 -0
  49. package/sdk-core/{src → core/src}/telemetry/metrics.rs +3 -58
  50. package/sdk-core/{src → core/src}/telemetry/mod.rs +8 -8
  51. package/sdk-core/{src → core/src}/telemetry/prometheus_server.rs +0 -0
  52. package/sdk-core/{src → core/src}/test_help/mod.rs +35 -83
  53. package/sdk-core/{src → core/src}/worker/activities/activity_heartbeat_manager.rs +95 -42
  54. package/sdk-core/core/src/worker/activities/local_activities.rs +973 -0
  55. package/sdk-core/{src → core/src}/worker/activities.rs +52 -33
  56. package/sdk-core/{src → core/src}/worker/dispatcher.rs +8 -6
  57. package/sdk-core/{src → core/src}/worker/mod.rs +347 -221
  58. package/sdk-core/core/src/worker/wft_delivery.rs +81 -0
  59. package/sdk-core/{src → core/src}/workflow/bridge.rs +5 -2
  60. package/sdk-core/{src → core/src}/workflow/driven_workflow.rs +17 -7
  61. package/sdk-core/{src → core/src}/workflow/history_update.rs +33 -7
  62. package/sdk-core/{src → core/src/workflow}/machines/activity_state_machine.rs +26 -26
  63. package/sdk-core/{src → core/src/workflow}/machines/cancel_external_state_machine.rs +8 -11
  64. package/sdk-core/{src → core/src/workflow}/machines/cancel_workflow_state_machine.rs +19 -21
  65. package/sdk-core/{src → core/src/workflow}/machines/child_workflow_state_machine.rs +20 -31
  66. package/sdk-core/{src → core/src/workflow}/machines/complete_workflow_state_machine.rs +3 -5
  67. package/sdk-core/{src → core/src/workflow}/machines/continue_as_new_workflow_state_machine.rs +18 -18
  68. package/sdk-core/{src → core/src/workflow}/machines/fail_workflow_state_machine.rs +5 -6
  69. package/sdk-core/core/src/workflow/machines/local_activity_state_machine.rs +1451 -0
  70. package/sdk-core/{src → core/src/workflow}/machines/mod.rs +54 -107
  71. package/sdk-core/{src → core/src/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
  72. package/sdk-core/{src → core/src/workflow}/machines/patch_state_machine.rs +29 -30
  73. package/sdk-core/{src → core/src/workflow}/machines/side_effect_state_machine.rs +0 -0
  74. package/sdk-core/{src → core/src/workflow}/machines/signal_external_state_machine.rs +17 -19
  75. package/sdk-core/{src → core/src/workflow}/machines/timer_state_machine.rs +20 -21
  76. package/sdk-core/{src → core/src/workflow}/machines/transition_coverage.rs +5 -2
  77. package/sdk-core/{src → core/src/workflow}/machines/upsert_search_attributes_state_machine.rs +0 -0
  78. package/sdk-core/core/src/workflow/machines/workflow_machines/local_acts.rs +96 -0
  79. package/sdk-core/{src → core/src/workflow}/machines/workflow_machines.rs +357 -171
  80. package/sdk-core/{src → core/src/workflow}/machines/workflow_task_state_machine.rs +1 -1
  81. package/sdk-core/{src → core/src}/workflow/mod.rs +200 -39
  82. package/sdk-core/{src → core/src}/workflow/workflow_tasks/cache_manager.rs +0 -0
  83. package/sdk-core/{src → core/src}/workflow/workflow_tasks/concurrency_manager.rs +38 -5
  84. package/sdk-core/{src → core/src}/workflow/workflow_tasks/mod.rs +317 -103
  85. package/sdk-core/{test_utils → core-api}/Cargo.toml +10 -7
  86. package/sdk-core/{src → core-api/src}/errors.rs +42 -92
  87. package/sdk-core/core-api/src/lib.rs +158 -0
  88. package/sdk-core/{src/worker/config.rs → core-api/src/worker.rs} +18 -23
  89. package/sdk-core/etc/deps.svg +156 -0
  90. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +5 -5
  91. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +3 -5
  92. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +7 -1
  93. package/sdk-core/histories/fail_wf_task.bin +0 -0
  94. package/sdk-core/histories/timer_workflow_history.bin +0 -0
  95. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +44 -13
  96. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +19 -1
  97. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +1 -1
  98. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +9 -0
  99. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +1 -0
  100. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +1 -0
  101. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +13 -0
  102. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +14 -7
  103. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +176 -18
  104. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
  105. package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +11 -0
  106. package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +3 -0
  107. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +156 -7
  108. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +135 -104
  109. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
  110. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +78 -0
  111. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +205 -0
  112. package/sdk-core/protos/local/temporal/sdk/core/bridge/service.proto +61 -0
  113. package/sdk-core/protos/local/{child_workflow.proto → temporal/sdk/core/child_workflow/child_workflow.proto} +1 -1
  114. package/sdk-core/protos/local/{common.proto → temporal/sdk/core/common/common.proto} +5 -3
  115. package/sdk-core/protos/local/{core_interface.proto → temporal/sdk/core/core_interface.proto} +10 -10
  116. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
  117. package/sdk-core/protos/local/{workflow_activation.proto → temporal/sdk/core/workflow_activation/workflow_activation.proto} +35 -11
  118. package/sdk-core/protos/local/{workflow_commands.proto → temporal/sdk/core/workflow_commands/workflow_commands.proto} +55 -4
  119. package/sdk-core/protos/local/{workflow_completion.proto → temporal/sdk/core/workflow_completion/workflow_completion.proto} +3 -3
  120. package/sdk-core/sdk/Cargo.toml +32 -0
  121. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/conversions.rs +0 -0
  122. package/sdk-core/sdk/src/lib.rs +699 -0
  123. package/sdk-core/sdk/src/payload_converter.rs +11 -0
  124. package/sdk-core/sdk/src/workflow_context/options.rs +180 -0
  125. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_context.rs +201 -124
  126. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_future.rs +63 -30
  127. package/sdk-core/sdk-core-protos/Cargo.toml +10 -0
  128. package/sdk-core/sdk-core-protos/build.rs +28 -6
  129. package/sdk-core/sdk-core-protos/src/constants.rs +7 -0
  130. package/sdk-core/{src/test_help → sdk-core-protos/src}/history_builder.rs +134 -49
  131. package/sdk-core/sdk-core-protos/src/history_info.rs +216 -0
  132. package/sdk-core/sdk-core-protos/src/lib.rs +601 -168
  133. package/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
  134. package/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  135. package/sdk-core/test-utils/Cargo.toml +32 -0
  136. package/sdk-core/{src/test_help → test-utils/src}/canned_histories.rs +59 -78
  137. package/sdk-core/test-utils/src/histfetch.rs +28 -0
  138. package/sdk-core/{test_utils → test-utils}/src/lib.rs +131 -68
  139. package/sdk-core/tests/integ_tests/client_tests.rs +1 -1
  140. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -7
  141. package/sdk-core/tests/integ_tests/polling_tests.rs +12 -11
  142. package/sdk-core/tests/integ_tests/queries_tests.rs +82 -78
  143. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +91 -71
  144. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +3 -4
  145. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +2 -4
  146. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +4 -6
  147. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +4 -6
  148. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -4
  149. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +496 -0
  150. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +5 -8
  151. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +125 -0
  152. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +7 -13
  153. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +33 -5
  154. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +12 -16
  155. package/sdk-core/tests/integ_tests/workflow_tests.rs +85 -82
  156. package/sdk-core/tests/load_tests.rs +6 -6
  157. package/sdk-core/tests/main.rs +2 -2
  158. package/src/conversions.rs +24 -21
  159. package/src/errors.rs +8 -0
  160. package/src/lib.rs +323 -211
  161. package/sdk-core/protos/local/activity_result.proto +0 -46
  162. package/sdk-core/protos/local/activity_task.proto +0 -66
  163. package/sdk-core/src/core_tests/retry.rs +0 -147
  164. package/sdk-core/src/lib.rs +0 -403
  165. package/sdk-core/src/machines/local_activity_state_machine.rs +0 -117
  166. package/sdk-core/src/pending_activations.rs +0 -249
  167. package/sdk-core/src/protosext/mod.rs +0 -160
  168. package/sdk-core/src/prototype_rust_sdk.rs +0 -412
  169. package/sdk-core/src/task_token.rs +0 -20
  170. package/sdk-core/src/test_help/history_info.rs +0 -157
@@ -34,17 +34,24 @@ option csharp_namespace = "Temporal.Api.WorkflowService.V1";
34
34
 
35
35
  import "temporal/api/workflowservice/v1/request_response.proto";
36
36
 
37
- // WorkflowService API is exposed to provide support for long running applications. Application is expected to call
38
- // StartWorkflowExecution to create an instance for each instance of long running workflow. Such applications are expected
39
- // to have a worker which regularly polls for WorkflowTask and ActivityTask from the WorkflowService. For each
40
- // WorkflowTask, application is expected to process the history of events for that session and respond back with next
41
- // commands. For each ActivityTask, application is expected to execute the actual logic for that task and respond back
42
- // with completion or failure. Worker is expected to regularly heartbeat while activity task is running.
37
+ // WorkflowService API defines how Temporal SDKs and other clients interact with the Temporal server
38
+ // to create and interact with workflows and activities.
39
+ //
40
+ // Users are expected to call `StartWorkflowExecution` to create a new workflow execution.
41
+ //
42
+ // To drive workflows, a worker using a Temporal SDK must exist which regularly polls for workflow
43
+ // and activity tasks from the service. For each workflow task, the sdk must process the
44
+ // (incremental or complete) event history and respond back with any newly generated commands.
45
+ //
46
+ // For each activity task, the worker is expected to execute the user's code which implements that
47
+ // activity, responding with completion or failure.
43
48
  service WorkflowService {
44
49
 
45
- // RegisterNamespace creates a new namespace which can be used as a container for all resources. Namespace is a top level
46
- // entity within Temporal, used as a container for all resources like workflow executions, task queues, etc. Namespace
47
- // acts as a sandbox and provides isolation for all resources within the namespace. All resources belongs to exactly one
50
+ // RegisterNamespace creates a new namespace which can be used as a container for all resources.
51
+ //
52
+ // A Namespace is a top level entity within Temporal, and is used as a container for resources
53
+ // like workflow executions, task queues, etc. A Namespace acts as a sandbox and provides
54
+ // isolation for all resources within the namespace. All resources belongs to exactly one
48
55
  // namespace.
49
56
  rpc RegisterNamespace (RegisterNamespaceRequest) returns (RegisterNamespaceResponse) {
50
57
  }
@@ -57,169 +64,189 @@ service WorkflowService {
57
64
  rpc ListNamespaces (ListNamespacesRequest) returns (ListNamespacesResponse) {
58
65
  }
59
66
 
67
+ // UpdateNamespace is used to update the information and configuration of a registered
68
+ // namespace.
69
+ //
60
70
  // (-- api-linter: core::0134::method-signature=disabled
61
71
  // aip.dev/not-precedent: UpdateNamespace RPC doesn't follow Google API format. --)
62
72
  // (-- api-linter: core::0134::response-message-name=disabled
63
73
  // aip.dev/not-precedent: UpdateNamespace RPC doesn't follow Google API format. --)
64
- // UpdateNamespace is used to update the information and configuration for a registered namespace.
65
74
  rpc UpdateNamespace (UpdateNamespaceRequest) returns (UpdateNamespaceResponse) {
66
75
  }
67
76
 
68
- // DeprecateNamespace is used to update state of a registered namespace to DEPRECATED. Once the namespace is deprecated
69
- // it cannot be used to start new workflow executions. Existing workflow executions will continue to run on
70
- // deprecated namespaces.
77
+ // DeprecateNamespace is used to update the state of a registered namespace to DEPRECATED.
78
+ //
79
+ // Once the namespace is deprecated it cannot be used to start new workflow executions. Existing
80
+ // workflow executions will continue to run on deprecated namespaces.
81
+ // Deprecated.
71
82
  rpc DeprecateNamespace (DeprecateNamespaceRequest) returns (DeprecateNamespaceResponse) {
72
83
  }
73
84
 
74
- // StartWorkflowExecution starts a new long running workflow instance. It will create the instance with
75
- // 'WorkflowExecutionStarted' event in history and also schedule the first WorkflowTask for the worker to make the
76
- // first command for this instance. It will return 'WorkflowExecutionAlreadyStartedFailure', if an instance already
77
- // exists with same workflowId.
85
+ // StartWorkflowExecution starts a new workflow execution.
86
+ //
87
+ // It will create the execution with a `WORKFLOW_EXECUTION_STARTED` event in its history and
88
+ // also schedule the first workflow task. Returns `WorkflowExecutionAlreadyStarted`, if an
89
+ // instance already exists with same workflow id.
78
90
  rpc StartWorkflowExecution (StartWorkflowExecutionRequest) returns (StartWorkflowExecutionResponse) {
79
91
  }
80
92
 
81
- // GetWorkflowExecutionHistory returns the history of specified workflow execution. It fails with 'NotFoundFailure' if specified workflow
82
- // execution in unknown to the service.
93
+ // GetWorkflowExecutionHistory returns the history of specified workflow execution. Fails with
94
+ // `NotFound` if the specified workflow execution is unknown to the service.
83
95
  rpc GetWorkflowExecutionHistory (GetWorkflowExecutionHistoryRequest) returns (GetWorkflowExecutionHistoryResponse) {
84
96
  }
85
97
 
86
- // PollWorkflowTaskQueue is called by application worker to process WorkflowTask from a specific task queue. A
87
- // WorkflowTask is dispatched to callers for active workflow executions, with pending workflow tasks.
88
- // Application is then expected to call 'RespondWorkflowTaskCompleted' API when it is done processing the WorkflowTask.
89
- // It will also create a 'WorkflowTaskStarted' event in the history for that session before handing off WorkflowTask to
90
- // application worker.
98
+ // PollWorkflowTaskQueue is called by workers to make progress on workflows.
99
+ //
100
+ // A WorkflowTask is dispatched to callers for active workflow executions with pending workflow
101
+ // tasks. The worker is expected to call `RespondWorkflowTaskCompleted` when it is done
102
+ // processing the task. The service will create a `WorkflowTaskStarted` event in the history for
103
+ // this task before handing it to the worker.
91
104
  rpc PollWorkflowTaskQueue (PollWorkflowTaskQueueRequest) returns (PollWorkflowTaskQueueResponse) {
92
105
  }
93
106
 
94
- // RespondWorkflowTaskCompleted is called by application worker to complete a WorkflowTask handed as a result of
95
- // 'PollWorkflowTaskQueue' API call. Completing a WorkflowTask will result in new events for the workflow execution and
96
- // potentially new ActivityTask being created for corresponding commands. It will also create a WorkflowTaskCompleted
97
- // event in the history for that session. Use the 'taskToken' provided as response of PollWorkflowTaskQueue API call
98
- // for completing the WorkflowTask.
99
- // The response could contain a new workflow task if there is one or if the request asking for one.
107
+ // RespondWorkflowTaskCompleted is called by workers to successfully complete workflow tasks
108
+ // they received from `PollWorkflowTaskQueue`.
109
+ //
110
+ // Completing a WorkflowTask will write a `WORKFLOW_TASK_COMPLETED` event to the workflow's
111
+ // history, along with events corresponding to whatever commands the SDK generated while
112
+ // executing the task (ex timer started, activity task scheduled, etc).
100
113
  rpc RespondWorkflowTaskCompleted (RespondWorkflowTaskCompletedRequest) returns (RespondWorkflowTaskCompletedResponse) {
101
114
  }
102
115
 
103
- // RespondWorkflowTaskFailed is called by application worker to indicate failure. This results in
104
- // WorkflowTaskFailedEvent written to the history and a new WorkflowTask created. This API can be used by client to
105
- // either clear sticky task queue or report any panics during WorkflowTask processing. Temporal will only append first
106
- // WorkflowTaskFailed event to the history of workflow execution for consecutive failures.
116
+ // RespondWorkflowTaskFailed is called by workers to indicate the processing of a workflow task
117
+ // failed.
118
+ //
119
+ // This results in a `WORKFLOW_TASK_FAILED` event written to the history, and a new workflow
120
+ // task will be scheduled. This API can be used to report unhandled failures resulting from
121
+ // applying the workflow task.
122
+ //
123
+ // Temporal will only append first WorkflowTaskFailed event to the history of workflow execution
124
+ // for consecutive failures.
107
125
  rpc RespondWorkflowTaskFailed (RespondWorkflowTaskFailedRequest) returns (RespondWorkflowTaskFailedResponse) {
108
126
  }
109
127
 
110
- // PollActivityTaskQueue is called by application worker to process ActivityTask from a specific task queue. ActivityTask
111
- // is dispatched to callers whenever a ScheduleTask command is made for a workflow execution.
112
- // Application is expected to call 'RespondActivityTaskCompleted' or 'RespondActivityTaskFailed' once it is done
128
+ // PollActivityTaskQueue is called by workers to process activity tasks from a specific task
129
+ // queue.
130
+ //
131
+ // The worker is expected to call one of the `RespondActivityTaskXXX` methods when it is done
113
132
  // processing the task.
114
- // Application also needs to call 'RecordActivityTaskHeartbeat' API within 'heartbeatTimeoutSeconds' interval to
115
- // prevent the Task from getting timed out. An in memory event 'ActivityTaskStarted' is also written to mutable state
116
- // before the ActivityTask is dispatched to application Worker. 'ActivityTaskStarted' and Activity finish event:
117
- // 'ActivityTaskCompleted' / 'ActivityTaskFailed' / 'ActivityTaskTimedout' will both be written to Workflow execution
118
- // history when Activity is finished.
133
+ //
134
+ // An activity task is dispatched whenever a `SCHEDULE_ACTIVITY_TASK` command is produced during
135
+ // workflow execution. An in memory `ACTIVITY_TASK_STARTED` event is written to mutable state
136
+ // before the task is dispatched to the worker. The started event, and the final event
137
+ // (`ACTIVITY_TASK_COMPLETED` / `ACTIVITY_TASK_FAILED` / `ACTIVITY_TASK_TIMED_OUT`) will both be
138
+ // written permanently to Workflow execution history when Activity is finished. This is done to
139
+ // avoid writing many events in the case of a failure/retry loop.
119
140
  rpc PollActivityTaskQueue (PollActivityTaskQueueRequest) returns (PollActivityTaskQueueResponse) {
120
141
  }
121
142
 
122
- // RecordActivityTaskHeartbeat is called by application worker while it is processing an ActivityTask. If worker fails
123
- // to heartbeat within 'heartbeatTimeoutSeconds' interval for the ActivityTask, then it will be marked as timedout and
124
- // 'ActivityTaskTimedOut' event will be written to the workflow history. Calling 'RecordActivityTaskHeartbeat' will
125
- // fail with 'NotFoundFailure' in such situations. Use the 'taskToken' provided as response of
126
- // PollActivityTaskQueue API call for heart beating.
143
+ // RecordActivityTaskHeartbeat is optionally called by workers while they execute activities.
144
+ //
145
+ // If worker fails to heartbeat within the `heartbeat_timeout` interval for the activity task,
146
+ // then it will be marked as timed out and an `ACTIVITY_TASK_TIMED_OUT` event will be written to
147
+ // the workflow history. Calling `RecordActivityTaskHeartbeat` will fail with `NotFound` in
148
+ // such situations, in that event, the SDK should request cancellation of the activity.
127
149
  rpc RecordActivityTaskHeartbeat (RecordActivityTaskHeartbeatRequest) returns (RecordActivityTaskHeartbeatResponse) {
128
150
  }
129
151
 
152
+ // See `RecordActivityTaskHeartbeat`. This version allows clients to record heartbeats by
153
+ // namespace/workflow id/activity id instead of task token.
154
+ //
130
155
  // (-- api-linter: core::0136::prepositions=disabled
131
156
  // aip.dev/not-precedent: "By" is used to indicate request type. --)
132
- // RecordActivityTaskHeartbeatById is called by application worker while it is processing an ActivityTask. If worker fails
133
- // to heartbeat within 'heartbeatTimeoutSeconds' interval for the ActivityTask, then it will be marked as timed out and
134
- // 'ActivityTaskTimedOut' event will be written to the workflow history. Calling 'RecordActivityTaskHeartbeatById' will
135
- // fail with 'NotFoundFailure' in such situations. Instead of using 'taskToken' like in RecordActivityTaskHeartbeat,
136
- // use Namespace, WorkflowId and ActivityId
137
157
  rpc RecordActivityTaskHeartbeatById (RecordActivityTaskHeartbeatByIdRequest) returns (RecordActivityTaskHeartbeatByIdResponse) {
138
158
  }
139
159
 
140
- // RespondActivityTaskCompleted is called by application worker when it is done processing an ActivityTask. It will
141
- // result in a new 'ActivityTaskCompleted' event being written to the workflow history and a new WorkflowTask
142
- // created for the workflow so new commands could be made. Use the 'taskToken' provided as response of
143
- // PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
144
- // anymore due to activity timeout.
160
+ // RespondActivityTaskCompleted is called by workers when they successfully complete an activity
161
+ // task.
162
+ //
163
+ // This results in a new `ACTIVITY_TASK_COMPLETED` event being written to the workflow history
164
+ // and a new workflow task created for the workflow. Fails with `NotFound` if the task token is
165
+ // no longer valid due to activity timeout, already being completed, or never having existed.
145
166
  rpc RespondActivityTaskCompleted (RespondActivityTaskCompletedRequest) returns (RespondActivityTaskCompletedResponse) {
146
167
  }
147
168
 
169
+ // See `RecordActivityTaskCompleted`. This version allows clients to record completions by
170
+ // namespace/workflow id/activity id instead of task token.
171
+ //
148
172
  // (-- api-linter: core::0136::prepositions=disabled
149
173
  // aip.dev/not-precedent: "By" is used to indicate request type. --)
150
- // RespondActivityTaskCompletedById is called by application worker when it is done processing an ActivityTask.
151
- // It will result in a new 'ActivityTaskCompleted' event being written to the workflow history and a new WorkflowTask
152
- // created for the workflow so new commands could be made. Similar to RespondActivityTaskCompleted but use Namespace,
153
- // WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
154
- // if the these Ids are not valid anymore due to activity timeout.
155
174
  rpc RespondActivityTaskCompletedById (RespondActivityTaskCompletedByIdRequest) returns (RespondActivityTaskCompletedByIdResponse) {
156
175
  }
157
176
 
158
- // RespondActivityTaskFailed is called by application worker when it is done processing an ActivityTask. It will
159
- // result in a new 'ActivityTaskFailed' event being written to the workflow history and a new WorkflowTask
160
- // created for the workflow instance so new commands could be made. Use the 'taskToken' provided as response of
161
- // PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
162
- // anymore due to activity timeout.
177
+ // RespondActivityTaskFailed is called by workers when processing an activity task fails.
178
+ //
179
+ // This results in a new `ACTIVITY_TASK_FAILED` event being written to the workflow history and
180
+ // a new workflow task created for the workflow. Fails with `NotFound` if the task token is no
181
+ // longer valid due to activity timeout, already being completed, or never having existed.
163
182
  rpc RespondActivityTaskFailed (RespondActivityTaskFailedRequest) returns (RespondActivityTaskFailedResponse) {
164
183
  }
165
184
 
185
+ // See `RecordActivityTaskFailed`. This version allows clients to record failures by
186
+ // namespace/workflow id/activity id instead of task token.
187
+ //
166
188
  // (-- api-linter: core::0136::prepositions=disabled
167
189
  // aip.dev/not-precedent: "By" is used to indicate request type. --)
168
- // RespondActivityTaskFailedById is called by application worker when it is done processing an ActivityTask.
169
- // It will result in a new 'ActivityTaskFailed' event being written to the workflow history and a new WorkflowTask
170
- // created for the workflow instance so new commands could be made. Similar to RespondActivityTaskFailed but use
171
- // Namespace, WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
172
- // if the these Ids are not valid anymore due to activity timeout.
173
190
  rpc RespondActivityTaskFailedById (RespondActivityTaskFailedByIdRequest) returns (RespondActivityTaskFailedByIdResponse) {
174
191
  }
175
192
 
176
- // RespondActivityTaskCanceled is called by application worker when it is successfully canceled an ActivityTask. It will
177
- // result in a new 'ActivityTaskCanceled' event being written to the workflow history and a new WorkflowTask
178
- // created for the workflow instance so new commands could be made. Use the 'taskToken' provided as response of
179
- // PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
180
- // anymore due to activity timeout.
193
+ // RespondActivityTaskFailed is called by workers when processing an activity task fails.
194
+ //
195
+ // This results in a new `ACTIVITY_TASK_CANCELED` event being written to the workflow history
196
+ // and a new workflow task created for the workflow. Fails with `NotFound` if the task token is
197
+ // no longer valid due to activity timeout, already being completed, or never having existed.
181
198
  rpc RespondActivityTaskCanceled (RespondActivityTaskCanceledRequest) returns (RespondActivityTaskCanceledResponse) {
182
199
  }
183
200
 
201
+ // See `RecordActivityTaskCanceled`. This version allows clients to record failures by
202
+ // namespace/workflow id/activity id instead of task token.
203
+ //
184
204
  // (-- api-linter: core::0136::prepositions=disabled
185
205
  // aip.dev/not-precedent: "By" is used to indicate request type. --)
186
- // RespondActivityTaskCanceledById is called by application worker when it is successfully canceled an ActivityTask.
187
- // It will result in a new 'ActivityTaskCanceled' event being written to the workflow history and a new WorkflowTask
188
- // created for the workflow instance so new commands could be made. Similar to RespondActivityTaskCanceled but use
189
- // Namespace, WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
190
- // if the these Ids are not valid anymore due to activity timeout.
191
206
  rpc RespondActivityTaskCanceledById (RespondActivityTaskCanceledByIdRequest) returns (RespondActivityTaskCanceledByIdResponse) {
192
207
  }
193
208
 
194
- // RequestCancelWorkflowExecution is called by application worker when it wants to request cancellation of a workflow instance.
195
- // It will result in a new 'WorkflowExecutionCancelRequested' event being written to the workflow history and a new WorkflowTask
196
- // created for the workflow instance so new commands could be made. It fails with 'NotFoundFailure' if the workflow is not valid
197
- // anymore due to completion or doesn't exist.
209
+ // RequestCancelWorkflowExecution is called by workers when they want to request cancellation of
210
+ // a workflow execution.
211
+ //
212
+ // This result in a new `WORKFLOW_EXECUTION_CANCEL_REQUESTED` event being written to the
213
+ // workflow history and a new workflow task created for the workflow. Fails with `NotFound` if
214
+ // the workflow is already completed or doesn't exist.
198
215
  rpc RequestCancelWorkflowExecution (RequestCancelWorkflowExecutionRequest) returns (RequestCancelWorkflowExecutionResponse) {
199
216
  }
200
217
 
201
- // SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
202
- // WorkflowExecutionSignaled event recorded in the history and a workflow task being created for the execution.
218
+ // SignalWorkflowExecution is used to send a signal to a running workflow execution.
219
+ //
220
+ // This results in a `WORKFLOW_EXECUTION_SIGNALED` event recorded in the history and a workflow
221
+ // task being created for the execution.
203
222
  rpc SignalWorkflowExecution (SignalWorkflowExecutionRequest) returns (SignalWorkflowExecutionResponse) {
204
223
  }
205
224
 
225
+ // SignalWithStartWorkflowExecution is used to ensure a signal is sent to a workflow, even if
226
+ // it isn't yet started.
227
+ //
228
+ // If the workflow is running, a `WORKFLOW_EXECUTION_SIGNALED` event is recorded in the history
229
+ // and a workflow task is generated.
230
+ //
231
+ // If the workflow is not running or not found, then the workflow is created with
232
+ // `WORKFLOW_EXECUTION_STARTED` and `WORKFLOW_EXECUTION_SIGNALED` events in its history, and a
233
+ // workflow task is generated.
234
+ //
206
235
  // (-- api-linter: core::0136::prepositions=disabled
207
236
  // aip.dev/not-precedent: "With" is used to indicate combined operation. --)
208
- // SignalWithStartWorkflowExecution is used to ensure sending signal to a workflow.
209
- // If the workflow is running, this results in WorkflowExecutionSignaled event being recorded in the history
210
- // and a workflow task being created for the execution.
211
- // If the workflow is not running or not found, this results in WorkflowExecutionStarted and WorkflowExecutionSignaled
212
- // events being recorded in history, and a workflow task being created for the execution
213
237
  rpc SignalWithStartWorkflowExecution (SignalWithStartWorkflowExecutionRequest) returns (SignalWithStartWorkflowExecutionResponse) {
214
238
  }
215
239
 
216
- // ResetWorkflowExecution reset an existing workflow execution to WorkflowTaskCompleted event(exclusive).
217
- // And it will immediately terminating the current execution instance.
240
+ // ResetWorkflowExecution will reset an existing workflow execution to a specified
241
+ // `WORKFLOW_TASK_COMPLETED` event (exclusive). It will immediately terminate the current
242
+ // execution instance.
243
+ // TODO: Does exclusive here mean *just* the completed event, or also WFT started? Otherwise the task is doomed to time out?
218
244
  rpc ResetWorkflowExecution (ResetWorkflowExecutionRequest) returns (ResetWorkflowExecutionResponse) {
219
245
  }
220
246
 
221
- // TerminateWorkflowExecution terminates an existing workflow execution by recording WorkflowExecutionTerminated event
222
- // in the history and immediately terminating the execution instance.
247
+ // TerminateWorkflowExecution terminates an existing workflow execution by recording a
248
+ // `WORKFLOW_EXECUTION_TERMINATED` event in the history and immediately terminating the
249
+ // execution instance.
223
250
  rpc TerminateWorkflowExecution (TerminateWorkflowExecutionRequest) returns (TerminateWorkflowExecutionResponse) {
224
251
  }
225
252
 
@@ -251,20 +278,25 @@ service WorkflowService {
251
278
  rpc GetSearchAttributes (GetSearchAttributesRequest) returns (GetSearchAttributesResponse) {
252
279
  }
253
280
 
254
- // RespondQueryTaskCompleted is called by application worker to complete a QueryTask (which is a WorkflowTask for query)
255
- // as a result of 'PollWorkflowTaskQueue' API call. Completing a QueryTask will unblock the client call to 'QueryWorkflow'
256
- // API and return the query result to client as a response to 'QueryWorkflow' API call.
281
+ // RespondQueryTaskCompleted is called by workers to complete queries which were delivered on
282
+ // the `query` (not `queries`) field of a `PollWorkflowTaskQueueResponse`.
283
+ //
284
+ // Completing the query will unblock the corresponding client call to `QueryWorkflow` and return
285
+ // the query result a response.
257
286
  rpc RespondQueryTaskCompleted (RespondQueryTaskCompletedRequest) returns (RespondQueryTaskCompletedResponse) {
258
287
  }
259
288
 
260
- // ResetStickyTaskQueue resets the sticky task queue related information in mutable state of a given workflow.
289
+ // ResetStickyTaskQueue resets the sticky task queue related information in the mutable state of
290
+ // a given workflow. This is prudent for workers to perform if a workflow has been paged out of
291
+ // their cache.
292
+ //
261
293
  // Things cleared are:
262
294
  // 1. StickyTaskQueue
263
295
  // 2. StickyScheduleToStartTimeout
264
296
  rpc ResetStickyTaskQueue (ResetStickyTaskQueueRequest) returns (ResetStickyTaskQueueResponse) {
265
297
  }
266
298
 
267
- // QueryWorkflow returns query result for a specified workflow execution
299
+ // QueryWorkflow requests a query be executed for a specified workflow execution.
268
300
  rpc QueryWorkflow (QueryWorkflowRequest) returns (QueryWorkflowResponse) {
269
301
  }
270
302
 
@@ -272,8 +304,7 @@ service WorkflowService {
272
304
  rpc DescribeWorkflowExecution (DescribeWorkflowExecutionRequest) returns (DescribeWorkflowExecutionResponse) {
273
305
  }
274
306
 
275
- // DescribeTaskQueue returns information about the target task queue, right now this API returns the
276
- // pollers which polled this task queue in last few minutes.
307
+ // DescribeTaskQueue returns information about the target task queue.
277
308
  rpc DescribeTaskQueue (DescribeTaskQueueRequest) returns (DescribeTaskQueueResponse) {
278
309
  }
279
310
 
@@ -0,0 +1,78 @@
1
+ syntax = "proto3";
2
+
3
+ package coresdk.activity_result;
4
+
5
+ import "google/protobuf/duration.proto";
6
+ import "google/protobuf/timestamp.proto";
7
+ import "temporal/api/failure/v1/message.proto";
8
+ import "temporal/sdk/core/common/common.proto";
9
+
10
+ /**
11
+ * Used to report activity completions to core
12
+ */
13
+ message ActivityExecutionResult {
14
+ oneof status {
15
+ Success completed = 1;
16
+ Failure failed = 2;
17
+ Cancellation cancelled = 3;
18
+ WillCompleteAsync will_complete_async = 4;
19
+ }
20
+ }
21
+
22
+ // Used to report activity resolutions to lang. IE: This is what the activities are resolved with
23
+ // in the workflow.
24
+ message ActivityResolution {
25
+ oneof status {
26
+ Success completed = 1;
27
+ Failure failed = 2;
28
+ Cancellation cancelled = 3;
29
+ DoBackoff backoff = 4;
30
+ }
31
+ }
32
+
33
+ /** Used to report successful completion either when executing or resolving */
34
+ message Success {
35
+ common.Payload result = 1;
36
+ }
37
+
38
+ /** Used to report activity failure either when executing or resolving */
39
+ message Failure {
40
+ temporal.api.failure.v1.Failure failure = 1;
41
+ }
42
+
43
+ /**
44
+ * Used to report cancellation from both Core and Lang.
45
+ * When Lang reports a cancelled activity, it must put a CancelledFailure in the failure field.
46
+ * When Core reports a cancelled activity, it must put an ActivityFailure with CancelledFailure
47
+ * as the cause in the failure field.
48
+ */
49
+ message Cancellation {
50
+ temporal.api.failure.v1.Failure failure = 1;
51
+ }
52
+
53
+ /**
54
+ * Used in ActivityExecutionResult to notify Core that this Activity will complete asynchronously.
55
+ * Core will forget about this Activity and free up resources used to track this Activity.
56
+ */
57
+ message WillCompleteAsync {
58
+ }
59
+
60
+ /**
61
+ * Issued when a local activity needs to retry but also wants to back off more than would be
62
+ * reasonable to WFT heartbeat for. Lang is expected to schedule a timer for the duration
63
+ * and then start a local activity of the same type & same inputs with the provided attempt number
64
+ * after the timer has elapsed.
65
+ *
66
+ * This exists because Core does not have a concept of starting commands by itself, they originate
67
+ * from lang. So expecting lang to start the timer / next pass of the activity fits more smoothly.
68
+ */
69
+ message DoBackoff {
70
+ // The attempt number that lang should provide when scheduling the retry. If the LA failed
71
+ // on attempt 4 and we told lang to back off with a timer, this number will be 5.
72
+ uint32 attempt = 1;
73
+ google.protobuf.Duration backoff_duration = 2;
74
+ // The time the first attempt of this local activity was scheduled. Must be passed with attempt
75
+ // to the retry LA.
76
+ google.protobuf.Timestamp original_schedule_time = 3;
77
+ }
78
+
@@ -0,0 +1,78 @@
1
+ syntax = "proto3";
2
+
3
+ /**
4
+ * Definitions of the different activity tasks returned from [crate::Core::poll_task].
5
+ */
6
+ package coresdk.activity_task;
7
+
8
+ import "google/protobuf/duration.proto";
9
+ import "google/protobuf/timestamp.proto";
10
+ import "temporal/sdk/core/common/common.proto";
11
+
12
+ message ActivityTask {
13
+ /// A unique identifier for this task
14
+ bytes task_token = 1;
15
+ oneof variant {
16
+ /// Start activity execution.
17
+ Start start = 3;
18
+ /// Attempt to cancel activity execution.
19
+ Cancel cancel = 4;
20
+ }
21
+ }
22
+
23
+ // Begin executing an activity
24
+ message Start {
25
+ // The namespace the workflow lives in
26
+ string workflow_namespace = 1;
27
+ // The workflow's type name or function identifier
28
+ string workflow_type = 2;
29
+ // The workflow execution which requested this activity
30
+ common.WorkflowExecution workflow_execution = 3;
31
+ // The activity's ID
32
+ string activity_id = 4;
33
+ // The activity's type name or function identifier
34
+ string activity_type = 5;
35
+ map<string, common.Payload> header_fields = 6;
36
+ // Arguments to the activity
37
+ repeated common.Payload input = 7;
38
+ // The last details that were recorded by a heartbeat when this task was generated
39
+ repeated common.Payload heartbeat_details = 8;
40
+ // When the task was *first* scheduled
41
+ google.protobuf.Timestamp scheduled_time = 9;
42
+ // When this current attempt at the task was scheduled
43
+ google.protobuf.Timestamp current_attempt_scheduled_time = 10;
44
+ // When this attempt was started, which is to say when core received it by polling.
45
+ google.protobuf.Timestamp started_time = 11;
46
+ uint32 attempt = 12;
47
+
48
+ // Timeout from the first schedule time to completion
49
+ google.protobuf.Duration schedule_to_close_timeout = 13;
50
+ // Timeout from starting an attempt to reporting its result
51
+ google.protobuf.Duration start_to_close_timeout = 14;
52
+ // If set a heartbeat must be reported within this interval
53
+ google.protobuf.Duration heartbeat_timeout = 15;
54
+ // This is an actual retry policy the service uses. It can be different from the one provided
55
+ // (or not) during activity scheduling as the service can override the provided one in case its
56
+ // values are not specified or exceed configured system limits.
57
+ common.RetryPolicy retry_policy = 16;
58
+
59
+ // Set to true if this is a local activity. Note that heartbeating does not apply to local
60
+ // activities.
61
+ bool is_local = 17;
62
+ }
63
+
64
+ /// Attempt to cancel a running activity
65
+ message Cancel {
66
+ ActivityCancelReason reason = 1;
67
+ }
68
+
69
+ enum ActivityCancelReason {
70
+ /// The activity no longer exists according to server (may be already completed)
71
+ NOT_FOUND = 0;
72
+ /// Activity was explicitly cancelled
73
+ CANCELLED = 1;
74
+ /// Activity timed out
75
+ TIMED_OUT = 2;
76
+ }
77
+
78
+