@temporalio/core-bridge 1.6.0 → 1.7.1

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 (138) hide show
  1. package/Cargo.lock +520 -456
  2. package/lib/index.d.ts +8 -6
  3. package/lib/index.js.map +1 -1
  4. package/package.json +8 -3
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.buildkite/docker/Dockerfile +2 -2
  11. package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
  12. package/sdk-core/.buildkite/pipeline.yml +1 -1
  13. package/sdk-core/.github/workflows/heavy.yml +1 -0
  14. package/sdk-core/README.md +13 -7
  15. package/sdk-core/client/src/lib.rs +27 -9
  16. package/sdk-core/client/src/metrics.rs +17 -8
  17. package/sdk-core/client/src/raw.rs +3 -3
  18. package/sdk-core/core/Cargo.toml +3 -4
  19. package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
  20. package/sdk-core/core/src/abstractions.rs +197 -18
  21. package/sdk-core/core/src/core_tests/activity_tasks.rs +137 -45
  22. package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
  23. package/sdk-core/core/src/core_tests/determinism.rs +212 -2
  24. package/sdk-core/core/src/core_tests/local_activities.rs +183 -36
  25. package/sdk-core/core/src/core_tests/queries.rs +32 -14
  26. package/sdk-core/core/src/core_tests/workers.rs +8 -5
  27. package/sdk-core/core/src/core_tests/workflow_tasks.rs +340 -51
  28. package/sdk-core/core/src/ephemeral_server/mod.rs +110 -8
  29. package/sdk-core/core/src/internal_flags.rs +141 -0
  30. package/sdk-core/core/src/lib.rs +14 -9
  31. package/sdk-core/core/src/replay/mod.rs +16 -27
  32. package/sdk-core/core/src/telemetry/metrics.rs +69 -35
  33. package/sdk-core/core/src/telemetry/mod.rs +38 -14
  34. package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
  35. package/sdk-core/core/src/test_help/mod.rs +65 -13
  36. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +119 -160
  37. package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  38. package/sdk-core/core/src/worker/activities/local_activities.rs +122 -6
  39. package/sdk-core/core/src/worker/activities.rs +347 -173
  40. package/sdk-core/core/src/worker/client/mocks.rs +22 -2
  41. package/sdk-core/core/src/worker/client.rs +18 -2
  42. package/sdk-core/core/src/worker/mod.rs +137 -44
  43. package/sdk-core/core/src/worker/workflow/history_update.rs +132 -51
  44. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +207 -166
  45. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +6 -7
  46. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -7
  47. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +157 -82
  48. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +12 -12
  49. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +6 -7
  50. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +13 -15
  51. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +170 -60
  52. package/sdk-core/core/src/worker/workflow/machines/mod.rs +24 -16
  53. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +6 -8
  54. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +320 -204
  55. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +10 -13
  56. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +15 -23
  57. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +187 -46
  58. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +237 -111
  59. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +13 -13
  60. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +10 -6
  61. package/sdk-core/core/src/worker/workflow/managed_run.rs +81 -62
  62. package/sdk-core/core/src/worker/workflow/mod.rs +341 -79
  63. package/sdk-core/core/src/worker/workflow/run_cache.rs +18 -11
  64. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +15 -3
  65. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +2 -0
  66. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +75 -52
  67. package/sdk-core/core-api/Cargo.toml +0 -1
  68. package/sdk-core/core-api/src/lib.rs +13 -7
  69. package/sdk-core/core-api/src/telemetry.rs +4 -6
  70. package/sdk-core/core-api/src/worker.rs +5 -0
  71. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +80 -55
  72. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +22 -68
  73. package/sdk-core/histories/ends_empty_wft_complete.bin +0 -0
  74. package/sdk-core/histories/old_change_marker_format.bin +0 -0
  75. package/sdk-core/protos/api_upstream/.github/CODEOWNERS +2 -1
  76. package/sdk-core/protos/api_upstream/Makefile +1 -1
  77. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +5 -17
  78. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +11 -0
  79. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +1 -6
  80. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +6 -6
  81. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +5 -0
  82. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +22 -6
  83. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +48 -19
  84. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -0
  85. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +3 -0
  86. package/sdk-core/protos/api_upstream/temporal/api/{enums/v1/interaction_type.proto → protocol/v1/message.proto} +29 -11
  87. package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  88. package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +111 -0
  89. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +59 -28
  90. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +2 -2
  91. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +7 -8
  92. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +10 -7
  93. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +19 -30
  94. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  95. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  96. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +8 -0
  97. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +65 -60
  98. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +85 -84
  99. package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +9 -3
  100. package/sdk-core/sdk/Cargo.toml +1 -1
  101. package/sdk-core/sdk/src/lib.rs +21 -5
  102. package/sdk-core/sdk/src/workflow_context/options.rs +7 -1
  103. package/sdk-core/sdk/src/workflow_context.rs +24 -17
  104. package/sdk-core/sdk/src/workflow_future.rs +9 -3
  105. package/sdk-core/sdk-core-protos/src/history_builder.rs +114 -89
  106. package/sdk-core/sdk-core-protos/src/history_info.rs +6 -1
  107. package/sdk-core/sdk-core-protos/src/lib.rs +205 -64
  108. package/sdk-core/test-utils/src/canned_histories.rs +106 -296
  109. package/sdk-core/test-utils/src/lib.rs +32 -5
  110. package/sdk-core/tests/heavy_tests.rs +10 -43
  111. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  112. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -3
  113. package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
  114. package/sdk-core/tests/integ_tests/polling_tests.rs +3 -8
  115. package/sdk-core/tests/integ_tests/queries_tests.rs +4 -2
  116. package/sdk-core/tests/integ_tests/visibility_tests.rs +34 -23
  117. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +97 -81
  118. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  119. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -0
  120. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +80 -3
  121. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +5 -1
  122. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +1 -0
  123. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +25 -3
  124. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
  125. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +30 -0
  126. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +64 -0
  127. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  128. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +4 -0
  129. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -1
  130. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +7 -2
  131. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -7
  132. package/sdk-core/tests/integ_tests/workflow_tests.rs +8 -8
  133. package/sdk-core/tests/main.rs +16 -25
  134. package/sdk-core/tests/runner.rs +11 -9
  135. package/src/conversions.rs +14 -8
  136. package/src/runtime.rs +9 -8
  137. package/ts/index.ts +8 -6
  138. package/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +0 -87
@@ -1,11 +1,12 @@
1
1
  syntax = "proto3";
2
2
 
3
- /**
3
+ /*
4
4
  * Definitions for commands from a workflow in lang SDK to core. While a workflow processes a batch
5
5
  * of activation jobs, it accumulates these commands to be sent back to core to conclude that
6
6
  * activation.
7
7
  */
8
8
  package coresdk.workflow_commands;
9
+ option ruby_package = "Temporalio::Bridge::Api::WorkflowCommands";
9
10
 
10
11
  import "google/protobuf/duration.proto";
11
12
  import "google/protobuf/timestamp.proto";
@@ -40,118 +41,118 @@ message WorkflowCommand {
40
41
  }
41
42
 
42
43
  message StartTimer {
43
- /// Lang's incremental sequence number, used as the operation identifier
44
+ // Lang's incremental sequence number, used as the operation identifier
44
45
  uint32 seq = 1;
45
46
  google.protobuf.Duration start_to_fire_timeout = 2;
46
47
  }
47
48
 
48
49
  message CancelTimer {
49
- /// Lang's incremental sequence number as passed to `StartTimer`
50
+ // Lang's incremental sequence number as passed to `StartTimer`
50
51
  uint32 seq = 1;
51
52
  }
52
53
 
53
54
  message ScheduleActivity {
54
- /// Lang's incremental sequence number, used as the operation identifier
55
+ // Lang's incremental sequence number, used as the operation identifier
55
56
  uint32 seq = 1;
56
57
  string activity_id = 2;
57
58
  string activity_type = 3;
58
59
  // The name of the task queue to place this activity request in
59
60
  string task_queue = 5;
60
61
  map<string, temporal.api.common.v1.Payload> headers = 6;
61
- /// Arguments/input to the activity. Called "input" upstream.
62
+ // Arguments/input to the activity. Called "input" upstream.
62
63
  repeated temporal.api.common.v1.Payload arguments = 7;
63
- /// Indicates how long the caller is willing to wait for an activity completion. Limits how long
64
- /// retries will be attempted. Either this or start_to_close_timeout_seconds must be specified.
65
- /// When not specified defaults to the workflow execution timeout.
64
+ // Indicates how long the caller is willing to wait for an activity completion. Limits how long
65
+ // retries will be attempted. Either this or start_to_close_timeout_seconds must be specified.
66
+ // When not specified defaults to the workflow execution timeout.
66
67
  google.protobuf.Duration schedule_to_close_timeout = 8;
67
- /// Limits time an activity task can stay in a task queue before a worker picks it up. This
68
- /// timeout is always non retryable as all a retry would achieve is to put it back into the same
69
- /// queue. Defaults to schedule_to_close_timeout or workflow execution timeout if not specified.
68
+ // Limits time an activity task can stay in a task queue before a worker picks it up. This
69
+ // timeout is always non retryable as all a retry would achieve is to put it back into the same
70
+ // queue. Defaults to schedule_to_close_timeout or workflow execution timeout if not specified.
70
71
  google.protobuf.Duration schedule_to_start_timeout = 9;
71
- /// Maximum time an activity is allowed to execute after a pick up by a worker. This timeout is
72
- /// always retryable. Either this or schedule_to_close_timeout must be specified.
72
+ // Maximum time an activity is allowed to execute after a pick up by a worker. This timeout is
73
+ // always retryable. Either this or schedule_to_close_timeout must be specified.
73
74
  google.protobuf.Duration start_to_close_timeout = 10;
74
- /// Maximum time allowed between successful worker heartbeats.
75
+ // Maximum time allowed between successful worker heartbeats.
75
76
  google.protobuf.Duration heartbeat_timeout = 11;
76
- /// Activities are provided by a default retry policy controlled through the service dynamic
77
- /// configuration. Retries are happening up to schedule_to_close_timeout. To disable retries set
78
- /// retry_policy.maximum_attempts to 1.
77
+ // Activities are provided by a default retry policy controlled through the service dynamic
78
+ // configuration. Retries are happening up to schedule_to_close_timeout. To disable retries set
79
+ // retry_policy.maximum_attempts to 1.
79
80
  temporal.api.common.v1.RetryPolicy retry_policy = 12;
80
- /// Defines how the workflow will wait (or not) for cancellation of the activity to be confirmed
81
+ // Defines how the workflow will wait (or not) for cancellation of the activity to be confirmed
81
82
  ActivityCancellationType cancellation_type = 13;
82
- /// If set, the worker will not tell the service that it can immediately start executing this
83
- /// activity. When unset/default, workers will always attempt to do so if activity execution
84
- /// slots are available.
83
+ // If set, the worker will not tell the service that it can immediately start executing this
84
+ // activity. When unset/default, workers will always attempt to do so if activity execution
85
+ // slots are available.
85
86
  bool do_not_eagerly_execute = 14;
86
87
  }
87
88
 
88
89
  message ScheduleLocalActivity {
89
- /// Lang's incremental sequence number, used as the operation identifier
90
+ // Lang's incremental sequence number, used as the operation identifier
90
91
  uint32 seq = 1;
91
92
  string activity_id = 2;
92
93
  string activity_type = 3;
93
- /// Local activities can start with a non-1 attempt, if lang has been told to backoff using
94
- /// a timer before retrying. It should pass the attempt number from a `DoBackoff` activity
95
- /// resolution.
94
+ // Local activities can start with a non-1 attempt, if lang has been told to backoff using
95
+ // a timer before retrying. It should pass the attempt number from a `DoBackoff` activity
96
+ // resolution.
96
97
  uint32 attempt = 4;
97
- /// If this local activity is a retry (as per the attempt field) this needs to be the original
98
- /// scheduling time (as provided in `DoBackoff`)
98
+ // If this local activity is a retry (as per the attempt field) this needs to be the original
99
+ // scheduling time (as provided in `DoBackoff`)
99
100
  google.protobuf.Timestamp original_schedule_time = 5;
100
101
  map<string, temporal.api.common.v1.Payload> headers = 6;
101
- /// Arguments/input to the activity.
102
+ // Arguments/input to the activity.
102
103
  repeated temporal.api.common.v1.Payload arguments = 7;
103
- /// Indicates how long the caller is willing to wait for local activity completion. Limits how
104
- /// long retries will be attempted. When not specified defaults to the workflow execution
105
- /// timeout (which may be unset).
104
+ // Indicates how long the caller is willing to wait for local activity completion. Limits how
105
+ // long retries will be attempted. When not specified defaults to the workflow execution
106
+ // timeout (which may be unset).
106
107
  google.protobuf.Duration schedule_to_close_timeout = 8;
107
- /// Limits time the local activity can idle internally before being executed. That can happen if
108
- /// the worker is currently at max concurrent local activity executions. This timeout is always
109
- /// non retryable as all a retry would achieve is to put it back into the same queue. Defaults
110
- /// to `schedule_to_close_timeout` if not specified and that is set. Must be <=
111
- /// `schedule_to_close_timeout` when set, otherwise, it will be clamped down.
108
+ // Limits time the local activity can idle internally before being executed. That can happen if
109
+ // the worker is currently at max concurrent local activity executions. This timeout is always
110
+ // non retryable as all a retry would achieve is to put it back into the same queue. Defaults
111
+ // to `schedule_to_close_timeout` if not specified and that is set. Must be <=
112
+ // `schedule_to_close_timeout` when set, otherwise, it will be clamped down.
112
113
  google.protobuf.Duration schedule_to_start_timeout = 9;
113
- /// Maximum time the local activity is allowed to execute after the task is dispatched. This
114
- /// timeout is always retryable. Either or both of `schedule_to_close_timeout` and this must be
115
- /// specified. If set, this must be <= `schedule_to_close_timeout`, otherwise, it will be
116
- /// clamped down.
114
+ // Maximum time the local activity is allowed to execute after the task is dispatched. This
115
+ // timeout is always retryable. Either or both of `schedule_to_close_timeout` and this must be
116
+ // specified. If set, this must be <= `schedule_to_close_timeout`, otherwise, it will be
117
+ // clamped down.
117
118
  google.protobuf.Duration start_to_close_timeout = 10;
118
- /// Specify a retry policy for the local activity. By default local activities will be retried
119
- /// indefinitely.
119
+ // Specify a retry policy for the local activity. By default local activities will be retried
120
+ // indefinitely.
120
121
  temporal.api.common.v1.RetryPolicy retry_policy = 11;
121
- /// If the activity is retrying and backoff would exceed this value, lang will be told to
122
- /// schedule a timer and retry the activity after. Otherwise, backoff will happen internally in
123
- /// core. Defaults to 1 minute.
122
+ // If the activity is retrying and backoff would exceed this value, lang will be told to
123
+ // schedule a timer and retry the activity after. Otherwise, backoff will happen internally in
124
+ // core. Defaults to 1 minute.
124
125
  google.protobuf.Duration local_retry_threshold = 12;
125
- /// Defines how the workflow will wait (or not) for cancellation of the activity to be
126
- /// confirmed. Lang should default this to `WAIT_CANCELLATION_COMPLETED`, even though proto
127
- /// will default to `TRY_CANCEL` automatically.
126
+ // Defines how the workflow will wait (or not) for cancellation of the activity to be
127
+ // confirmed. Lang should default this to `WAIT_CANCELLATION_COMPLETED`, even though proto
128
+ // will default to `TRY_CANCEL` automatically.
128
129
  ActivityCancellationType cancellation_type = 13;
129
130
  }
130
131
 
131
132
  enum ActivityCancellationType {
132
- /// Initiate a cancellation request and immediately report cancellation to the workflow.
133
+ // Initiate a cancellation request and immediately report cancellation to the workflow.
133
134
  TRY_CANCEL = 0;
134
- /// Wait for activity cancellation completion. Note that activity must heartbeat to receive a
135
- /// cancellation notification. This can block the cancellation for a long time if activity
136
- /// doesn't heartbeat or chooses to ignore the cancellation request.
135
+ // Wait for activity cancellation completion. Note that activity must heartbeat to receive a
136
+ // cancellation notification. This can block the cancellation for a long time if activity
137
+ // doesn't heartbeat or chooses to ignore the cancellation request.
137
138
  WAIT_CANCELLATION_COMPLETED = 1;
138
- /// Do not request cancellation of the activity and immediately report cancellation to the
139
- /// workflow
139
+ // Do not request cancellation of the activity and immediately report cancellation to the
140
+ // workflow
140
141
  ABANDON = 2;
141
142
  }
142
143
 
143
144
  message RequestCancelActivity {
144
- /// Lang's incremental sequence number as passed to `ScheduleActivity`
145
+ // Lang's incremental sequence number as passed to `ScheduleActivity`
145
146
  uint32 seq = 1;
146
147
  }
147
148
 
148
149
  message RequestCancelLocalActivity {
149
- /// Lang's incremental sequence number as passed to `ScheduleLocalActivity`
150
+ // Lang's incremental sequence number as passed to `ScheduleLocalActivity`
150
151
  uint32 seq = 1;
151
152
  }
152
153
 
153
154
  message QueryResult {
154
- /// Corresponds to the id provided in the activation job
155
+ // Corresponds to the id provided in the activation job
155
156
  string query_id = 1;
156
157
  oneof variant {
157
158
  QuerySuccess succeeded = 2;
@@ -163,12 +164,12 @@ message QuerySuccess {
163
164
  temporal.api.common.v1.Payload response = 1;
164
165
  }
165
166
 
166
- /// Issued when the workflow completes successfully
167
+ // Issued when the workflow completes successfully
167
168
  message CompleteWorkflowExecution {
168
169
  temporal.api.common.v1.Payload result = 1;
169
170
  }
170
171
 
171
- /// Issued when the workflow errors out
172
+ // Issued when the workflow errors out
172
173
  message FailWorkflowExecution {
173
174
  temporal.api.failure.v1.Failure failure = 1;
174
175
  }
@@ -199,11 +200,11 @@ message ContinueAsNewWorkflowExecution {
199
200
  temporal.api.common.v1.RetryPolicy retry_policy = 9;
200
201
  }
201
202
 
202
- /// Indicate a workflow has completed as cancelled. Generally sent as a response to an activation
203
- /// containing a cancellation job.
203
+ // Indicate a workflow has completed as cancelled. Generally sent as a response to an activation
204
+ // containing a cancellation job.
204
205
  message CancelWorkflowExecution {}
205
206
 
206
- /// A request to set/check if a certain patch is present or not
207
+ // A request to set/check if a certain patch is present or not
207
208
  message SetPatchMarker {
208
209
  // A user-chosen identifier for this patch. If the same identifier is used in multiple places in
209
210
  // the code, those places are considered to be versioned as one unit. IE: The check call will
@@ -214,47 +215,47 @@ message SetPatchMarker {
214
215
  bool deprecated = 2;
215
216
  }
216
217
 
217
- /// Start a child workflow execution
218
+ // Start a child workflow execution
218
219
  message StartChildWorkflowExecution {
219
- /// Lang's incremental sequence number, used as the operation identifier
220
+ // Lang's incremental sequence number, used as the operation identifier
220
221
  uint32 seq = 1;
221
222
  string namespace = 2;
222
223
  string workflow_id = 3;
223
224
  string workflow_type = 4;
224
225
  string task_queue = 5;
225
226
  repeated temporal.api.common.v1.Payload input = 6;
226
- /// Total workflow execution timeout including retries and continue as new.
227
+ // Total workflow execution timeout including retries and continue as new.
227
228
  google.protobuf.Duration workflow_execution_timeout = 7;
228
- /// Timeout of a single workflow run.
229
+ // Timeout of a single workflow run.
229
230
  google.protobuf.Duration workflow_run_timeout = 8;
230
- /// Timeout of a single workflow task.
231
+ // Timeout of a single workflow task.
231
232
  google.protobuf.Duration workflow_task_timeout = 9;
232
- /// Default: PARENT_CLOSE_POLICY_TERMINATE.
233
+ // Default: PARENT_CLOSE_POLICY_TERMINATE.
233
234
  child_workflow.ParentClosePolicy parent_close_policy = 10;
234
235
  // string control = 11; (unused from StartChildWorkflowExecutionCommandAttributes)
235
236
  // Default: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE.
236
237
  temporal.api.enums.v1.WorkflowIdReusePolicy workflow_id_reuse_policy = 12;
237
238
  temporal.api.common.v1.RetryPolicy retry_policy = 13;
238
239
  string cron_schedule = 14;
239
- /// Header fields
240
+ // Header fields
240
241
  map<string, temporal.api.common.v1.Payload> headers = 15;
241
- /// Memo fields
242
+ // Memo fields
242
243
  map<string, temporal.api.common.v1.Payload> memo = 16;
243
- /// Search attributes
244
+ // Search attributes
244
245
  map<string, temporal.api.common.v1.Payload> search_attributes = 17;
245
- /// Defines behaviour of the underlying workflow when child workflow cancellation has been requested.
246
+ // Defines behaviour of the underlying workflow when child workflow cancellation has been requested.
246
247
  child_workflow.ChildWorkflowCancellationType cancellation_type = 18;
247
248
  }
248
249
 
249
- /// Cancel a child workflow
250
+ // Cancel a child workflow
250
251
  message CancelChildWorkflowExecution {
251
252
  // Sequence number as given to the `StartChildWorkflowExecution` command
252
253
  uint32 child_workflow_seq = 1;
253
254
  }
254
255
 
255
- /// Request cancellation of an external workflow execution (which may be a started child)
256
+ // Request cancellation of an external workflow execution (which may be a started child)
256
257
  message RequestCancelExternalWorkflowExecution {
257
- /// Lang's incremental sequence number, used as the operation identifier
258
+ // Lang's incremental sequence number, used as the operation identifier
258
259
  uint32 seq = 1;
259
260
  // What workflow is being targeted
260
261
  oneof target {
@@ -265,9 +266,9 @@ message RequestCancelExternalWorkflowExecution {
265
266
  }
266
267
  }
267
268
 
268
- /// Send a signal to an external or child workflow
269
+ // Send a signal to an external or child workflow
269
270
  message SignalExternalWorkflowExecution {
270
- /// Lang's incremental sequence number, used as the operation identifier
271
+ // Lang's incremental sequence number, used as the operation identifier
271
272
  uint32 seq = 1;
272
273
  // What workflow is being targeted
273
274
  oneof target {
@@ -276,23 +277,23 @@ message SignalExternalWorkflowExecution {
276
277
  // The desired target must be a child of the issuing workflow, and this is its workflow id
277
278
  string child_workflow_id = 3;
278
279
  }
279
- /// Name of the signal handler
280
+ // Name of the signal handler
280
281
  string signal_name = 4;
281
- /// Arguments for the handler
282
+ // Arguments for the handler
282
283
  repeated temporal.api.common.v1.Payload args = 5;
283
- /// Headers to attach to the signal
284
+ // Headers to attach to the signal
284
285
  map<string, temporal.api.common.v1.Payload> headers = 6;
285
286
  }
286
287
 
287
- /// Can be used to cancel not-already-sent `SignalExternalWorkflowExecution` commands
288
+ // Can be used to cancel not-already-sent `SignalExternalWorkflowExecution` commands
288
289
  message CancelSignalWorkflow {
289
- /// Lang's incremental sequence number as passed to `SignalExternalWorkflowExecution`
290
+ // Lang's incremental sequence number as passed to `SignalExternalWorkflowExecution`
290
291
  uint32 seq = 1;
291
292
  }
292
293
 
293
294
  message UpsertWorkflowSearchAttributes {
294
- /// SearchAttributes fields - equivalent to indexed_fields on api. Key = search index, Value =
295
- /// value?
295
+ // SearchAttributes fields - equivalent to indexed_fields on api. Key = search index, Value =
296
+ // value?
296
297
  map<string, temporal.api.common.v1.Payload> search_attributes = 1;
297
298
  }
298
299
 
@@ -1,12 +1,14 @@
1
1
  syntax = "proto3";
2
2
 
3
3
  package coresdk.workflow_completion;
4
+ option ruby_package = "Temporalio::Bridge::Api::WorkflowCompletion";
4
5
 
5
6
  import "temporal/api/failure/v1/message.proto";
7
+ import "temporal/api/enums/v1/failed_cause.proto";
6
8
  import "temporal/sdk/core/common/common.proto";
7
9
  import "temporal/sdk/core/workflow_commands/workflow_commands.proto";
8
10
 
9
- /// Result of a single workflow activation, reported from lang to core
11
+ // Result of a single workflow activation, reported from lang to core
10
12
  message WorkflowActivationCompletion {
11
13
  // The run id from the workflow activation you are completing
12
14
  string run_id = 1;
@@ -16,14 +18,18 @@ message WorkflowActivationCompletion {
16
18
  }
17
19
  }
18
20
 
19
- /// Successful workflow activation with a list of commands generated by the workflow execution
21
+ // Successful workflow activation with a list of commands generated by the workflow execution
20
22
  message Success {
21
23
  // A list of commands to send back to the temporal server
22
24
  repeated workflow_commands.WorkflowCommand commands = 1;
25
+ // Any internal flags which the lang SDK used in the processing of this activation
26
+ repeated uint32 used_internal_flags = 6;
23
27
  }
24
28
 
25
- /// Failure to activate or execute a workflow
29
+ // Failure to activate or execute a workflow
26
30
  message Failure {
27
31
  temporal.api.failure.v1.Failure failure = 1;
32
+ // Forces overriding the WFT failure cause
33
+ temporal.api.enums.v1.WorkflowTaskFailedCause force_cause = 2;
28
34
  }
29
35
 
@@ -25,7 +25,7 @@ parking_lot = { version = "0.12", features = ["send_guard"] }
25
25
  prost-types = { version = "0.4", package = "prost-wkt-types" }
26
26
  sha2 = "0.10"
27
27
  serde = "1.0"
28
- tokio = { version = "1.1", features = ["rt", "rt-multi-thread", "parking_lot", "time", "fs"] }
28
+ tokio = { version = "1.26", features = ["rt", "rt-multi-thread", "parking_lot", "time", "fs"] }
29
29
  tokio-util = { version = "0.7" }
30
30
  tokio-stream = "0.1"
31
31
  tonic = "0.8"
@@ -88,7 +88,7 @@ use temporal_sdk_core_protos::{
88
88
  common::NamespacedWorkflowExecution,
89
89
  workflow_activation::{
90
90
  resolve_child_workflow_execution_start::Status as ChildWorkflowStartStatus,
91
- workflow_activation_job::Variant, WorkflowActivation, WorkflowActivationJob,
91
+ workflow_activation_job::Variant, WorkflowActivation,
92
92
  },
93
93
  workflow_commands::{workflow_command, ContinueAsNewWorkflowExecution},
94
94
  workflow_completion::WorkflowActivationCompletion,
@@ -391,10 +391,10 @@ impl WorkflowHalf {
391
391
 
392
392
  // If the activation is to start a workflow, create a new workflow driver for it,
393
393
  // using the function associated with that workflow id
394
- if let Some(WorkflowActivationJob {
395
- variant: Some(Variant::StartWorkflow(sw)),
396
- }) = activation.jobs.get(0)
397
- {
394
+ if let Some(sw) = activation.jobs.iter().find_map(|j| match j.variant {
395
+ Some(Variant::StartWorkflow(ref sw)) => Some(sw),
396
+ _ => None,
397
+ }) {
398
398
  let workflow_type = &sw.workflow_type;
399
399
  let wf_fns_borrow = self.workflow_fns.borrow();
400
400
  let wf_function = wf_fns_borrow
@@ -549,11 +549,13 @@ pub enum TimerResult {
549
549
  }
550
550
 
551
551
  /// Successful result of sending a signal to an external workflow
552
+ #[derive(Debug)]
552
553
  pub struct SignalExternalOk;
553
554
  /// Result of awaiting on sending a signal to an external workflow
554
555
  pub type SignalExternalWfResult = Result<SignalExternalOk, Failure>;
555
556
 
556
557
  /// Successful result of sending a cancel request to an external workflow
558
+ #[derive(Debug)]
557
559
  pub struct CancelExternalOk;
558
560
  /// Result of awaiting on sending a cancel request to an external workflow
559
561
  pub type CancelExternalWfResult = Result<CancelExternalOk, Failure>;
@@ -656,6 +658,20 @@ pub enum CancellableID {
656
658
  },
657
659
  }
658
660
 
661
+ impl CancellableID {
662
+ /// Returns the type-specific sequence number used for this command
663
+ pub fn seq_num(&self) -> u32 {
664
+ match self {
665
+ CancellableID::Timer(seq) => *seq,
666
+ CancellableID::Activity(seq) => *seq,
667
+ CancellableID::LocalActivity(seq) => *seq,
668
+ CancellableID::ChildWorkflow(seq) => *seq,
669
+ CancellableID::SignalExternalWorkflow(seq) => *seq,
670
+ CancellableID::ExternalWorkflow { seqnum, .. } => *seqnum,
671
+ }
672
+ }
673
+ }
674
+
659
675
  #[derive(derive_more::From)]
660
676
  #[allow(clippy::large_enum_variant)]
661
677
  enum RustWfCmd {
@@ -9,7 +9,10 @@ use temporal_sdk_core_protos::{
9
9
  StartChildWorkflowExecution,
10
10
  },
11
11
  },
12
- temporal::api::common::v1::{Payload, RetryPolicy},
12
+ temporal::api::{
13
+ common::v1::{Payload, RetryPolicy},
14
+ enums::v1::ParentClosePolicy,
15
+ },
13
16
  };
14
17
 
15
18
  // TODO: Before release, probably best to avoid using proto types entirely here. They're awkward.
@@ -180,6 +183,8 @@ pub struct ChildWorkflowOptions {
180
183
  pub cancel_type: ChildWorkflowCancellationType,
181
184
  /// Common options
182
185
  pub options: WorkflowOptions,
186
+ /// How to respond to parent workflow ending
187
+ pub parent_close_policy: ParentClosePolicy,
183
188
  }
184
189
 
185
190
  impl IntoWorkflowCommand for ChildWorkflowOptions {
@@ -203,6 +208,7 @@ impl IntoWorkflowCommand for ChildWorkflowOptions {
203
208
  workflow_task_timeout: self.options.task_timeout.and_then(|d| d.try_into().ok()),
204
209
  search_attributes: self.options.search_attributes.unwrap_or_default(),
205
210
  cron_schedule: self.options.cron_schedule.unwrap_or_default(),
211
+ parent_close_policy: self.parent_close_policy as i32,
206
212
  ..Default::default()
207
213
  }
208
214
  }
@@ -34,7 +34,8 @@ use temporal_sdk_core_protos::{
34
34
  workflow_commands::{
35
35
  request_cancel_external_workflow_execution as cancel_we,
36
36
  signal_external_workflow_execution as sig_we, workflow_command,
37
- ModifyWorkflowProperties, RequestCancelExternalWorkflowExecution, SetPatchMarker,
37
+ CancelChildWorkflowExecution, ModifyWorkflowProperties,
38
+ RequestCancelExternalWorkflowExecution, SetPatchMarker,
38
39
  SignalExternalWorkflowExecution, StartTimer, UpsertWorkflowSearchAttributes,
39
40
  },
40
41
  },
@@ -98,6 +99,7 @@ pub struct WfContextSharedData {
98
99
  pub changes: HashMap<String, bool>,
99
100
  pub is_replaying: bool,
100
101
  pub wf_time: Option<SystemTime>,
102
+ pub history_length: u32,
101
103
  }
102
104
 
103
105
  // TODO: Dataconverter type interface to replace Payloads here. Possibly just use serde
@@ -148,6 +150,11 @@ impl WfContext {
148
150
  self.shared.read().wf_time
149
151
  }
150
152
 
153
+ /// Return the length of history so far at this point in the workflow
154
+ pub fn history_length(&self) -> u32 {
155
+ self.shared.read().history_length
156
+ }
157
+
151
158
  pub(crate) fn get_shared_data(&self) -> Arc<RwLock<WfContextSharedData>> {
152
159
  self.shared.clone()
153
160
  }
@@ -550,16 +557,16 @@ impl<'a> Future for LATimerBackoffFut<'a> {
550
557
  }
551
558
  let poll_res = self.current_fut.poll_unpin(cx);
552
559
  if let Poll::Ready(ref r) = poll_res {
553
- // If we've already said we want to cancel, don't schedule the backoff timer. Just
554
- // return cancel status. This can happen if cancel comes after the LA says it wants to
555
- // back off but before we have scheduled the timer.
556
- if self.did_cancel.load(Ordering::Acquire) {
557
- return Poll::Ready(ActivityResolution {
558
- status: Some(activity_resolution::Status::Cancelled(Default::default())),
559
- });
560
- }
561
-
562
560
  if let Some(activity_resolution::Status::Backoff(b)) = r.status.as_ref() {
561
+ // If we've already said we want to cancel, don't schedule the backoff timer. Just
562
+ // return cancel status. This can happen if cancel comes after the LA says it wants
563
+ // to back off but before we have scheduled the timer.
564
+ if self.did_cancel.load(Ordering::Acquire) {
565
+ return Poll::Ready(ActivityResolution {
566
+ status: Some(activity_resolution::Status::Cancelled(Default::default())),
567
+ });
568
+ }
569
+
563
570
  let timer_f = self.ctx.timer(
564
571
  b.backoff_duration
565
572
  .clone()
@@ -673,13 +680,13 @@ impl StartedChildWorkflow {
673
680
  }
674
681
 
675
682
  /// Cancel the child workflow
676
- pub fn cancel(&self, cx: &WfContext) -> impl Future<Output = CancelExternalWfResult> {
677
- let target = NamespacedWorkflowExecution {
678
- namespace: cx.namespace().to_string(),
679
- workflow_id: self.common.workflow_id.clone(),
680
- ..Default::default()
681
- };
682
- cx.cancel_external(target)
683
+ pub fn cancel(&self, cx: &WfContext) {
684
+ cx.send(RustWfCmd::NewNonblockingCmd(
685
+ CancelChildWorkflowExecution {
686
+ child_workflow_seq: self.common.result_future.cancellable_id.seq_num(),
687
+ }
688
+ .into(),
689
+ ));
683
690
  }
684
691
 
685
692
  /// Signal the child workflow
@@ -62,7 +62,9 @@ impl WorkflowFunction {
62
62
  // We need to mark the workflow future as unconstrained, otherwise Tokio will impose
63
63
  // an artificial limit on how many commands we can unblock in one poll round.
64
64
  // TODO: Now we *need* deadlock detection or we could hose the whole system
65
- inner: tokio::task::unconstrained((self.wf_func)(wf_context)).boxed(),
65
+ inner: tokio::task::unconstrained((self.wf_func)(wf_context))
66
+ .fuse()
67
+ .boxed(),
66
68
  incoming_commands: cmd_receiver,
67
69
  outgoing_completions,
68
70
  incoming_activations,
@@ -179,8 +181,11 @@ impl WorkflowFuture {
179
181
  Box::new(result.context("Child Workflow execution must have a result")?),
180
182
  ))?,
181
183
  Variant::UpdateRandomSeed(_) => (),
182
- Variant::QueryWorkflow(_) => {
183
- todo!()
184
+ Variant::QueryWorkflow(q) => {
185
+ error!(
186
+ "Queries are not implemented in the Rust SDK. Got query '{}'",
187
+ q.query_id
188
+ );
184
189
  }
185
190
  Variant::CancelWorkflow(_) => {
186
191
  // TODO: Cancel pending futures, etc
@@ -252,6 +257,7 @@ impl Future for WorkflowFuture {
252
257
  let mut wlock = self.ctx_shared.write();
253
258
  wlock.is_replaying = activation.is_replaying;
254
259
  wlock.wf_time = activation.timestamp.try_into_or_none();
260
+ wlock.history_length = activation.history_length;
255
261
  }
256
262
 
257
263
  let mut die_of_eviction_when_done = false;