temporal-ruby 0.0.0 → 0.0.1.pre.pre1

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -42
  3. data/lib/gen/temporal/api/command/v1/message_pb.rb +146 -0
  4. data/lib/gen/temporal/api/common/v1/message_pb.rb +67 -0
  5. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +35 -0
  6. data/lib/gen/temporal/api/enums/v1/common_pb.rb +34 -0
  7. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +62 -0
  8. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +60 -0
  9. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +31 -0
  10. data/lib/gen/temporal/api/enums/v1/query_pb.rb +31 -0
  11. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +30 -0
  12. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +82 -0
  13. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +55 -0
  14. data/lib/gen/temporal/api/failure/v1/message_pb.rb +81 -0
  15. data/lib/gen/temporal/api/filter/v1/message_pb.rb +38 -0
  16. data/lib/gen/temporal/api/history/v1/message_pb.rb +423 -0
  17. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +55 -0
  18. data/lib/gen/temporal/api/query/v1/message_pb.rb +36 -0
  19. data/lib/gen/temporal/api/replication/v1/message_pb.rb +27 -0
  20. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +60 -0
  21. data/lib/gen/temporal/api/version/v1/message_pb.rb +28 -0
  22. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +83 -0
  23. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +538 -0
  24. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +19 -0
  25. data/lib/gen/temporal/api/workflowservice/v1/service_services_pb.rb +223 -0
  26. data/lib/temporal-ruby.rb +1 -0
  27. data/lib/temporal.rb +137 -0
  28. data/lib/temporal/activity.rb +33 -0
  29. data/lib/temporal/activity/async_token.rb +34 -0
  30. data/lib/temporal/activity/context.rb +64 -0
  31. data/lib/temporal/activity/poller.rb +79 -0
  32. data/lib/temporal/activity/task_processor.rb +78 -0
  33. data/lib/temporal/activity/workflow_convenience_methods.rb +41 -0
  34. data/lib/temporal/client.rb +21 -0
  35. data/lib/temporal/client/errors.rb +8 -0
  36. data/lib/temporal/client/grpc_client.rb +345 -0
  37. data/lib/temporal/client/serializer.rb +31 -0
  38. data/lib/temporal/client/serializer/base.rb +23 -0
  39. data/lib/temporal/client/serializer/cancel_timer.rb +19 -0
  40. data/lib/temporal/client/serializer/complete_workflow.rb +20 -0
  41. data/lib/temporal/client/serializer/fail_workflow.rb +20 -0
  42. data/lib/temporal/client/serializer/failure.rb +29 -0
  43. data/lib/temporal/client/serializer/payload.rb +25 -0
  44. data/lib/temporal/client/serializer/record_marker.rb +23 -0
  45. data/lib/temporal/client/serializer/request_activity_cancellation.rb +19 -0
  46. data/lib/temporal/client/serializer/schedule_activity.rb +53 -0
  47. data/lib/temporal/client/serializer/start_child_workflow.rb +51 -0
  48. data/lib/temporal/client/serializer/start_timer.rb +20 -0
  49. data/lib/temporal/concerns/executable.rb +37 -0
  50. data/lib/temporal/concerns/typed.rb +40 -0
  51. data/lib/temporal/configuration.rb +44 -0
  52. data/lib/temporal/errors.rb +38 -0
  53. data/lib/temporal/executable_lookup.rb +25 -0
  54. data/lib/temporal/execution_options.rb +35 -0
  55. data/lib/temporal/json.rb +18 -0
  56. data/lib/temporal/metadata.rb +68 -0
  57. data/lib/temporal/metadata/activity.rb +27 -0
  58. data/lib/temporal/metadata/base.rb +17 -0
  59. data/lib/temporal/metadata/workflow.rb +22 -0
  60. data/lib/temporal/metadata/workflow_task.rb +25 -0
  61. data/lib/temporal/metrics.rb +37 -0
  62. data/lib/temporal/metrics_adapters/log.rb +33 -0
  63. data/lib/temporal/metrics_adapters/null.rb +9 -0
  64. data/lib/temporal/middleware/chain.rb +30 -0
  65. data/lib/temporal/middleware/entry.rb +9 -0
  66. data/lib/temporal/retry_policy.rb +27 -0
  67. data/lib/temporal/saga/concern.rb +23 -0
  68. data/lib/temporal/saga/result.rb +22 -0
  69. data/lib/temporal/saga/saga.rb +24 -0
  70. data/lib/temporal/testing.rb +50 -0
  71. data/lib/temporal/testing/future_registry.rb +27 -0
  72. data/lib/temporal/testing/local_activity_context.rb +17 -0
  73. data/lib/temporal/testing/local_workflow_context.rb +178 -0
  74. data/lib/temporal/testing/temporal_override.rb +121 -0
  75. data/lib/temporal/testing/workflow_execution.rb +44 -0
  76. data/lib/temporal/testing/workflow_override.rb +36 -0
  77. data/lib/temporal/thread_local_context.rb +14 -0
  78. data/lib/temporal/thread_pool.rb +63 -0
  79. data/lib/temporal/types.rb +7 -0
  80. data/lib/temporal/uuid.rb +19 -0
  81. data/lib/temporal/version.rb +1 -1
  82. data/lib/temporal/worker.rb +88 -0
  83. data/lib/temporal/workflow.rb +42 -0
  84. data/lib/temporal/workflow/command.rb +39 -0
  85. data/lib/temporal/workflow/command_state_machine.rb +48 -0
  86. data/lib/temporal/workflow/context.rb +243 -0
  87. data/lib/temporal/workflow/convenience_methods.rb +34 -0
  88. data/lib/temporal/workflow/dispatcher.rb +31 -0
  89. data/lib/temporal/workflow/execution_info.rb +51 -0
  90. data/lib/temporal/workflow/executor.rb +45 -0
  91. data/lib/temporal/workflow/future.rb +77 -0
  92. data/lib/temporal/workflow/history.rb +76 -0
  93. data/lib/temporal/workflow/history/event.rb +69 -0
  94. data/lib/temporal/workflow/history/event_target.rb +75 -0
  95. data/lib/temporal/workflow/history/window.rb +40 -0
  96. data/lib/temporal/workflow/poller.rb +67 -0
  97. data/lib/temporal/workflow/replay_aware_logger.rb +36 -0
  98. data/lib/temporal/workflow/state_manager.rb +342 -0
  99. data/lib/temporal/workflow/task_processor.rb +78 -0
  100. data/rbi/temporal-ruby.rbi +43 -0
  101. data/temporal.gemspec +10 -2
  102. metadata +186 -6
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: temporal/api/workflowservice/v1/service.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'temporal/api/workflowservice/v1/request_response_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_file("temporal/api/workflowservice/v1/service.proto", :syntax => :proto3) do
9
+ end
10
+ end
11
+
12
+ module Temporal
13
+ module Api
14
+ module WorkflowService
15
+ module V1
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,223 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: temporal/api/workflowservice/v1/service.proto for package 'Temporal.Api.WorkflowService.V1'
3
+ # Original file comments:
4
+ # The MIT License
5
+ #
6
+ # Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'grpc'
28
+ require 'temporal/api/workflowservice/v1/service_pb'
29
+
30
+ module Temporal
31
+ module Api
32
+ module WorkflowService
33
+ module V1
34
+ module WorkflowService
35
+ # WorkflowService API is exposed to provide support for long running applications. Application is expected to call
36
+ # StartWorkflowExecution to create an instance for each instance of long running workflow. Such applications are expected
37
+ # to have a worker which regularly polls for WorkflowTask and ActivityTask from the WorkflowService. For each
38
+ # WorkflowTask, application is expected to process the history of events for that session and respond back with next
39
+ # commands. For each ActivityTask, application is expected to execute the actual logic for that task and respond back
40
+ # with completion or failure. Worker is expected to regularly heartbeat while activity task is running.
41
+ class Service
42
+
43
+ include GRPC::GenericService
44
+
45
+ self.marshal_class_method = :encode
46
+ self.unmarshal_class_method = :decode
47
+ self.service_name = 'temporal.api.workflowservice.v1.WorkflowService'
48
+
49
+ # RegisterNamespace creates a new namespace which can be used as a container for all resources. Namespace is a top level
50
+ # entity within Temporal, used as a container for all resources like workflow executions, task queues, etc. Namespace
51
+ # acts as a sandbox and provides isolation for all resources within the namespace. All resources belongs to exactly one
52
+ # namespace.
53
+ rpc :RegisterNamespace, ::Temporal::Api::WorkflowService::V1::RegisterNamespaceRequest, ::Temporal::Api::WorkflowService::V1::RegisterNamespaceResponse
54
+ # DescribeNamespace returns the information and configuration for a registered namespace.
55
+ rpc :DescribeNamespace, ::Temporal::Api::WorkflowService::V1::DescribeNamespaceRequest, ::Temporal::Api::WorkflowService::V1::DescribeNamespaceResponse
56
+ # ListNamespaces returns the information and configuration for all namespaces.
57
+ rpc :ListNamespaces, ::Temporal::Api::WorkflowService::V1::ListNamespacesRequest, ::Temporal::Api::WorkflowService::V1::ListNamespacesResponse
58
+ # (-- api-linter: core::0134::method-signature=disabled
59
+ # aip.dev/not-precedent: UpdateNamespace RPC doesn't follow Google API format. --)
60
+ # (-- api-linter: core::0134::response-message-name=disabled
61
+ # aip.dev/not-precedent: UpdateNamespace RPC doesn't follow Google API format. --)
62
+ # UpdateNamespace is used to update the information and configuration for a registered namespace.
63
+ rpc :UpdateNamespace, ::Temporal::Api::WorkflowService::V1::UpdateNamespaceRequest, ::Temporal::Api::WorkflowService::V1::UpdateNamespaceResponse
64
+ # DeprecateNamespace is used to update state of a registered namespace to DEPRECATED. Once the namespace is deprecated
65
+ # it cannot be used to start new workflow executions. Existing workflow executions will continue to run on
66
+ # deprecated namespaces.
67
+ rpc :DeprecateNamespace, ::Temporal::Api::WorkflowService::V1::DeprecateNamespaceRequest, ::Temporal::Api::WorkflowService::V1::DeprecateNamespaceResponse
68
+ # StartWorkflowExecution starts a new long running workflow instance. It will create the instance with
69
+ # 'WorkflowExecutionStarted' event in history and also schedule the first WorkflowTask for the worker to make the
70
+ # first command for this instance. It will return 'WorkflowExecutionAlreadyStartedFailure', if an instance already
71
+ # exists with same workflowId.
72
+ rpc :StartWorkflowExecution, ::Temporal::Api::WorkflowService::V1::StartWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::StartWorkflowExecutionResponse
73
+ # GetWorkflowExecutionHistory returns the history of specified workflow execution. It fails with 'NotFoundFailure' if specified workflow
74
+ # execution in unknown to the service.
75
+ rpc :GetWorkflowExecutionHistory, ::Temporal::Api::WorkflowService::V1::GetWorkflowExecutionHistoryRequest, ::Temporal::Api::WorkflowService::V1::GetWorkflowExecutionHistoryResponse
76
+ # PollWorkflowTaskQueue is called by application worker to process WorkflowTask from a specific task queue. A
77
+ # WorkflowTask is dispatched to callers for active workflow executions, with pending workflow tasks.
78
+ # Application is then expected to call 'RespondWorkflowTaskCompleted' API when it is done processing the WorkflowTask.
79
+ # It will also create a 'WorkflowTaskStarted' event in the history for that session before handing off WorkflowTask to
80
+ # application worker.
81
+ rpc :PollWorkflowTaskQueue, ::Temporal::Api::WorkflowService::V1::PollWorkflowTaskQueueRequest, ::Temporal::Api::WorkflowService::V1::PollWorkflowTaskQueueResponse
82
+ # RespondWorkflowTaskCompleted is called by application worker to complete a WorkflowTask handed as a result of
83
+ # 'PollWorkflowTaskQueue' API call. Completing a WorkflowTask will result in new events for the workflow execution and
84
+ # potentially new ActivityTask being created for corresponding commands. It will also create a WorkflowTaskCompleted
85
+ # event in the history for that session. Use the 'taskToken' provided as response of PollWorkflowTaskQueue API call
86
+ # for completing the WorkflowTask.
87
+ # The response could contain a new workflow task if there is one or if the request asking for one.
88
+ rpc :RespondWorkflowTaskCompleted, ::Temporal::Api::WorkflowService::V1::RespondWorkflowTaskCompletedRequest, ::Temporal::Api::WorkflowService::V1::RespondWorkflowTaskCompletedResponse
89
+ # RespondWorkflowTaskFailed is called by application worker to indicate failure. This results in
90
+ # WorkflowTaskFailedEvent written to the history and a new WorkflowTask created. This API can be used by client to
91
+ # either clear sticky task queue or report any panics during WorkflowTask processing. Temporal will only append first
92
+ # WorkflowTaskFailed event to the history of workflow execution for consecutive failures.
93
+ rpc :RespondWorkflowTaskFailed, ::Temporal::Api::WorkflowService::V1::RespondWorkflowTaskFailedRequest, ::Temporal::Api::WorkflowService::V1::RespondWorkflowTaskFailedResponse
94
+ # PollActivityTaskQueue is called by application worker to process ActivityTask from a specific task queue. ActivityTask
95
+ # is dispatched to callers whenever a ScheduleTask command is made for a workflow execution.
96
+ # Application is expected to call 'RespondActivityTaskCompleted' or 'RespondActivityTaskFailed' once it is done
97
+ # processing the task.
98
+ # Application also needs to call 'RecordActivityTaskHeartbeat' API within 'heartbeatTimeoutSeconds' interval to
99
+ # prevent the task from getting timed out. An event 'ActivityTaskStarted' event is also written to workflow execution
100
+ # history before the ActivityTask is dispatched to application worker.
101
+ rpc :PollActivityTaskQueue, ::Temporal::Api::WorkflowService::V1::PollActivityTaskQueueRequest, ::Temporal::Api::WorkflowService::V1::PollActivityTaskQueueResponse
102
+ # RecordActivityTaskHeartbeat is called by application worker while it is processing an ActivityTask. If worker fails
103
+ # to heartbeat within 'heartbeatTimeoutSeconds' interval for the ActivityTask, then it will be marked as timedout and
104
+ # 'ActivityTaskTimedOut' event will be written to the workflow history. Calling 'RecordActivityTaskHeartbeat' will
105
+ # fail with 'NotFoundFailure' in such situations. Use the 'taskToken' provided as response of
106
+ # PollActivityTaskQueue API call for heart beating.
107
+ rpc :RecordActivityTaskHeartbeat, ::Temporal::Api::WorkflowService::V1::RecordActivityTaskHeartbeatRequest, ::Temporal::Api::WorkflowService::V1::RecordActivityTaskHeartbeatResponse
108
+ # (-- api-linter: core::0136::prepositions=disabled
109
+ # aip.dev/not-precedent: "By" is used to indicate request type. --)
110
+ # RecordActivityTaskHeartbeatById is called by application worker while it is processing an ActivityTask. If worker fails
111
+ # to heartbeat within 'heartbeatTimeoutSeconds' interval for the ActivityTask, then it will be marked as timed out and
112
+ # 'ActivityTaskTimedOut' event will be written to the workflow history. Calling 'RecordActivityTaskHeartbeatById' will
113
+ # fail with 'NotFoundFailure' in such situations. Instead of using 'taskToken' like in RecordActivityTaskHeartbeat,
114
+ # use Namespace, WorkflowId and ActivityId
115
+ rpc :RecordActivityTaskHeartbeatById, ::Temporal::Api::WorkflowService::V1::RecordActivityTaskHeartbeatByIdRequest, ::Temporal::Api::WorkflowService::V1::RecordActivityTaskHeartbeatByIdResponse
116
+ # RespondActivityTaskCompleted is called by application worker when it is done processing an ActivityTask. It will
117
+ # result in a new 'ActivityTaskCompleted' event being written to the workflow history and a new WorkflowTask
118
+ # created for the workflow so new commands could be made. Use the 'taskToken' provided as response of
119
+ # PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
120
+ # anymore due to activity timeout.
121
+ rpc :RespondActivityTaskCompleted, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCompletedRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCompletedResponse
122
+ # (-- api-linter: core::0136::prepositions=disabled
123
+ # aip.dev/not-precedent: "By" is used to indicate request type. --)
124
+ # RespondActivityTaskCompletedById is called by application worker when it is done processing an ActivityTask.
125
+ # It will result in a new 'ActivityTaskCompleted' event being written to the workflow history and a new WorkflowTask
126
+ # created for the workflow so new commands could be made. Similar to RespondActivityTaskCompleted but use Namespace,
127
+ # WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
128
+ # if the these Ids are not valid anymore due to activity timeout.
129
+ rpc :RespondActivityTaskCompletedById, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCompletedByIdRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCompletedByIdResponse
130
+ # RespondActivityTaskFailed is called by application worker when it is done processing an ActivityTask. It will
131
+ # result in a new 'ActivityTaskFailed' event being written to the workflow history and a new WorkflowTask
132
+ # created for the workflow instance so new commands could be made. Use the 'taskToken' provided as response of
133
+ # PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
134
+ # anymore due to activity timeout.
135
+ rpc :RespondActivityTaskFailed, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskFailedRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskFailedResponse
136
+ # (-- api-linter: core::0136::prepositions=disabled
137
+ # aip.dev/not-precedent: "By" is used to indicate request type. --)
138
+ # RespondActivityTaskFailedById is called by application worker when it is done processing an ActivityTask.
139
+ # It will result in a new 'ActivityTaskFailed' event being written to the workflow history and a new WorkflowTask
140
+ # created for the workflow instance so new commands could be made. Similar to RespondActivityTaskFailed but use
141
+ # Namespace, WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
142
+ # if the these Ids are not valid anymore due to activity timeout.
143
+ rpc :RespondActivityTaskFailedById, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskFailedByIdRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskFailedByIdResponse
144
+ # RespondActivityTaskCanceled is called by application worker when it is successfully canceled an ActivityTask. It will
145
+ # result in a new 'ActivityTaskCanceled' event being written to the workflow history and a new WorkflowTask
146
+ # created for the workflow instance so new commands could be made. Use the 'taskToken' provided as response of
147
+ # PollActivityTaskQueue API call for completion. It fails with 'NotFoundFailure' if the taskToken is not valid
148
+ # anymore due to activity timeout.
149
+ rpc :RespondActivityTaskCanceled, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCanceledRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCanceledResponse
150
+ # (-- api-linter: core::0136::prepositions=disabled
151
+ # aip.dev/not-precedent: "By" is used to indicate request type. --)
152
+ # RespondActivityTaskCanceledById is called by application worker when it is successfully canceled an ActivityTask.
153
+ # It will result in a new 'ActivityTaskCanceled' event being written to the workflow history and a new WorkflowTask
154
+ # created for the workflow instance so new commands could be made. Similar to RespondActivityTaskCanceled but use
155
+ # Namespace, WorkflowId and ActivityId instead of 'taskToken' for completion. It fails with 'NotFoundFailure'
156
+ # if the these Ids are not valid anymore due to activity timeout.
157
+ rpc :RespondActivityTaskCanceledById, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCanceledByIdRequest, ::Temporal::Api::WorkflowService::V1::RespondActivityTaskCanceledByIdResponse
158
+ # RequestCancelWorkflowExecution is called by application worker when it wants to request cancellation of a workflow instance.
159
+ # It will result in a new 'WorkflowExecutionCancelRequested' event being written to the workflow history and a new WorkflowTask
160
+ # created for the workflow instance so new commands could be made. It fails with 'NotFoundFailure' if the workflow is not valid
161
+ # anymore due to completion or doesn't exist.
162
+ rpc :RequestCancelWorkflowExecution, ::Temporal::Api::WorkflowService::V1::RequestCancelWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::RequestCancelWorkflowExecutionResponse
163
+ # SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
164
+ # WorkflowExecutionSignaled event recorded in the history and a workflow task being created for the execution.
165
+ rpc :SignalWorkflowExecution, ::Temporal::Api::WorkflowService::V1::SignalWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::SignalWorkflowExecutionResponse
166
+ # (-- api-linter: core::0136::prepositions=disabled
167
+ # aip.dev/not-precedent: "With" is used to indicate combined operation. --)
168
+ # SignalWithStartWorkflowExecution is used to ensure sending signal to a workflow.
169
+ # If the workflow is running, this results in WorkflowExecutionSignaled event being recorded in the history
170
+ # and a workflow task being created for the execution.
171
+ # If the workflow is not running or not found, this results in WorkflowExecutionStarted and WorkflowExecutionSignaled
172
+ # events being recorded in history, and a workflow task being created for the execution
173
+ rpc :SignalWithStartWorkflowExecution, ::Temporal::Api::WorkflowService::V1::SignalWithStartWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::SignalWithStartWorkflowExecutionResponse
174
+ # ResetWorkflowExecution reset an existing workflow execution to WorkflowTaskCompleted event(exclusive).
175
+ # And it will immediately terminating the current execution instance.
176
+ rpc :ResetWorkflowExecution, ::Temporal::Api::WorkflowService::V1::ResetWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::ResetWorkflowExecutionResponse
177
+ # TerminateWorkflowExecution terminates an existing workflow execution by recording WorkflowExecutionTerminated event
178
+ # in the history and immediately terminating the execution instance.
179
+ rpc :TerminateWorkflowExecution, ::Temporal::Api::WorkflowService::V1::TerminateWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::TerminateWorkflowExecutionResponse
180
+ # ListOpenWorkflowExecutions is a visibility API to list the open executions in a specific namespace.
181
+ rpc :ListOpenWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::ListOpenWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::ListOpenWorkflowExecutionsResponse
182
+ # ListClosedWorkflowExecutions is a visibility API to list the closed executions in a specific namespace.
183
+ rpc :ListClosedWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::ListClosedWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::ListClosedWorkflowExecutionsResponse
184
+ # ListWorkflowExecutions is a visibility API to list workflow executions in a specific namespace.
185
+ rpc :ListWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::ListWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::ListWorkflowExecutionsResponse
186
+ # ListArchivedWorkflowExecutions is a visibility API to list archived workflow executions in a specific namespace.
187
+ rpc :ListArchivedWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::ListArchivedWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::ListArchivedWorkflowExecutionsResponse
188
+ # ScanWorkflowExecutions is a visibility API to list large amount of workflow executions in a specific namespace without order.
189
+ rpc :ScanWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::ScanWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::ScanWorkflowExecutionsResponse
190
+ # CountWorkflowExecutions is a visibility API to count of workflow executions in a specific namespace.
191
+ rpc :CountWorkflowExecutions, ::Temporal::Api::WorkflowService::V1::CountWorkflowExecutionsRequest, ::Temporal::Api::WorkflowService::V1::CountWorkflowExecutionsResponse
192
+ # GetSearchAttributes is a visibility API to get all legal keys that could be used in list APIs
193
+ rpc :GetSearchAttributes, ::Temporal::Api::WorkflowService::V1::GetSearchAttributesRequest, ::Temporal::Api::WorkflowService::V1::GetSearchAttributesResponse
194
+ # RespondQueryTaskCompleted is called by application worker to complete a QueryTask (which is a WorkflowTask for query)
195
+ # as a result of 'PollWorkflowTaskQueue' API call. Completing a QueryTask will unblock the client call to 'QueryWorkflow'
196
+ # API and return the query result to client as a response to 'QueryWorkflow' API call.
197
+ rpc :RespondQueryTaskCompleted, ::Temporal::Api::WorkflowService::V1::RespondQueryTaskCompletedRequest, ::Temporal::Api::WorkflowService::V1::RespondQueryTaskCompletedResponse
198
+ # ResetStickyTaskQueue resets the sticky task queue related information in mutable state of a given workflow.
199
+ # Things cleared are:
200
+ # 1. StickyTaskQueue
201
+ # 2. StickyScheduleToStartTimeout
202
+ # 3. ClientLibraryVersion
203
+ # 4. ClientFeatureVersion
204
+ # 5. ClientImpl
205
+ rpc :ResetStickyTaskQueue, ::Temporal::Api::WorkflowService::V1::ResetStickyTaskQueueRequest, ::Temporal::Api::WorkflowService::V1::ResetStickyTaskQueueResponse
206
+ # QueryWorkflow returns query result for a specified workflow execution
207
+ rpc :QueryWorkflow, ::Temporal::Api::WorkflowService::V1::QueryWorkflowRequest, ::Temporal::Api::WorkflowService::V1::QueryWorkflowResponse
208
+ # DescribeWorkflowExecution returns information about the specified workflow execution.
209
+ rpc :DescribeWorkflowExecution, ::Temporal::Api::WorkflowService::V1::DescribeWorkflowExecutionRequest, ::Temporal::Api::WorkflowService::V1::DescribeWorkflowExecutionResponse
210
+ # DescribeTaskQueue returns information about the target task queue, right now this API returns the
211
+ # pollers which polled this task queue in last few minutes.
212
+ rpc :DescribeTaskQueue, ::Temporal::Api::WorkflowService::V1::DescribeTaskQueueRequest, ::Temporal::Api::WorkflowService::V1::DescribeTaskQueueResponse
213
+ # GetClusterInfo returns information about temporal cluster
214
+ rpc :GetClusterInfo, ::Temporal::Api::WorkflowService::V1::GetClusterInfoRequest, ::Temporal::Api::WorkflowService::V1::GetClusterInfoResponse
215
+ rpc :ListTaskQueuePartitions, ::Temporal::Api::WorkflowService::V1::ListTaskQueuePartitionsRequest, ::Temporal::Api::WorkflowService::V1::ListTaskQueuePartitionsResponse
216
+ end
217
+
218
+ Stub = Service.rpc_stub_class
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1 @@
1
+ require 'temporal'
@@ -0,0 +1,137 @@
1
+ # Protoc wants all of its generated files on the LOAD_PATH
2
+ $LOAD_PATH << File.expand_path('./gen', __dir__)
3
+
4
+ require 'securerandom'
5
+ require 'temporal/configuration'
6
+ require 'temporal/execution_options'
7
+ require 'temporal/client'
8
+ require 'temporal/activity'
9
+ require 'temporal/activity/async_token'
10
+ require 'temporal/workflow'
11
+ require 'temporal/workflow/history'
12
+ require 'temporal/workflow/execution_info'
13
+ require 'temporal/metrics'
14
+
15
+ module Temporal
16
+ class << self
17
+ def start_workflow(workflow, *input, **args)
18
+ options = args.delete(:options) || {}
19
+ input << args unless args.empty?
20
+
21
+ execution_options = ExecutionOptions.new(workflow, options)
22
+ workflow_id = options[:workflow_id] || SecureRandom.uuid
23
+
24
+ response = client.start_workflow_execution(
25
+ namespace: execution_options.namespace,
26
+ workflow_id: workflow_id,
27
+ workflow_name: execution_options.name,
28
+ task_queue: execution_options.task_queue,
29
+ input: input,
30
+ execution_timeout: execution_options.timeouts[:execution],
31
+ task_timeout: execution_options.timeouts[:task],
32
+ workflow_id_reuse_policy: options[:workflow_id_reuse_policy],
33
+ headers: execution_options.headers
34
+ )
35
+
36
+ response.run_id
37
+ end
38
+
39
+ def register_namespace(name, description = nil)
40
+ client.register_namespace(name: name, description: description)
41
+ end
42
+
43
+ def signal_workflow(workflow, signal, workflow_id, run_id, input = nil)
44
+ execution_options = ExecutionOptions.new(workflow)
45
+
46
+ client.signal_workflow_execution(
47
+ namespace: execution_options.namespace, # TODO: allow passing namespace instead
48
+ workflow_id: workflow_id,
49
+ run_id: run_id,
50
+ signal: signal,
51
+ input: input
52
+ )
53
+ end
54
+
55
+ def reset_workflow(namespace, workflow_id, run_id, workflow_task_id: nil, reason: 'manual reset')
56
+ workflow_task_id ||= get_last_completed_workflow_task_id(namespace, workflow_id, run_id)
57
+ raise Error, 'Could not find a completed workflow task event' unless workflow_task_id
58
+
59
+ response = client.reset_workflow_execution(
60
+ namespace: namespace,
61
+ workflow_id: workflow_id,
62
+ run_id: run_id,
63
+ reason: reason,
64
+ workflow_task_event_id: workflow_task_id
65
+ )
66
+
67
+ response.run_id
68
+ end
69
+
70
+ def fetch_workflow_execution_info(namespace, workflow_id, run_id)
71
+ response = client.describe_workflow_execution(
72
+ namespace: namespace,
73
+ workflow_id: workflow_id,
74
+ run_id: run_id
75
+ )
76
+
77
+ Workflow::ExecutionInfo.generate_from(response.workflow_execution_info)
78
+ end
79
+
80
+ def complete_activity(async_token, result = nil)
81
+ details = Activity::AsyncToken.decode(async_token)
82
+
83
+ client.respond_activity_task_completed_by_id(
84
+ namespace: details.namespace,
85
+ activity_id: details.activity_id,
86
+ workflow_id: details.workflow_id,
87
+ run_id: details.run_id,
88
+ result: result
89
+ )
90
+ end
91
+
92
+ def fail_activity(async_token, exception)
93
+ details = Activity::AsyncToken.decode(async_token)
94
+
95
+ client.respond_activity_task_failed_by_id(
96
+ namespace: details.namespace,
97
+ activity_id: details.activity_id,
98
+ workflow_id: details.workflow_id,
99
+ run_id: details.run_id,
100
+ exception: exception
101
+ )
102
+ end
103
+
104
+ def configure(&block)
105
+ yield configuration
106
+ end
107
+
108
+ def configuration
109
+ @configuration ||= Configuration.new
110
+ end
111
+
112
+ def logger
113
+ configuration.logger
114
+ end
115
+
116
+ def metrics
117
+ @metrics ||= Metrics.new(configuration.metrics_adapter)
118
+ end
119
+
120
+ private
121
+
122
+ def client
123
+ @client ||= Temporal::Client.generate
124
+ end
125
+
126
+ def get_last_completed_workflow_task_id(namespace, workflow_id, run_id)
127
+ history_response = client.get_workflow_execution_history(
128
+ namespace: namespace,
129
+ workflow_id: workflow_id,
130
+ run_id: run_id
131
+ )
132
+ history = Workflow::History.new(history_response.history.events)
133
+ workflow_task_event = history.get_last_completed_workflow_task
134
+ workflow_task_event&.id
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,33 @@
1
+ require 'temporal/activity/workflow_convenience_methods'
2
+ require 'temporal/concerns/executable'
3
+ require 'temporal/errors'
4
+
5
+ module Temporal
6
+ class Activity
7
+ extend WorkflowConvenienceMethods
8
+ extend Concerns::Executable
9
+
10
+ def self.execute_in_context(context, input)
11
+ activity = new(context)
12
+ activity.execute(*input)
13
+ end
14
+
15
+ def initialize(context)
16
+ @context = context
17
+ end
18
+
19
+ def execute(*_args)
20
+ raise NotImplementedError, '#execute method must be implemented by a subclass'
21
+ end
22
+
23
+ private
24
+
25
+ def activity
26
+ @context
27
+ end
28
+
29
+ def logger
30
+ activity.logger
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ require 'base64'
2
+
3
+ module Temporal
4
+ class Activity
5
+ class AsyncToken
6
+ SEPARATOR = '|'.freeze
7
+
8
+ attr_reader :namespace, :activity_id, :workflow_id, :run_id
9
+
10
+ def self.encode(namespace, activity_id, workflow_id, run_id)
11
+ new(namespace, activity_id, workflow_id, run_id).to_s
12
+ end
13
+
14
+ def self.decode(token)
15
+ string = Base64.urlsafe_decode64(token)
16
+ namespace, activity_id, workflow_id, run_id = string.split(SEPARATOR)
17
+
18
+ new(namespace, activity_id, workflow_id, run_id)
19
+ end
20
+
21
+ def initialize(namespace, activity_id, workflow_id, run_id)
22
+ @namespace = namespace
23
+ @activity_id = activity_id
24
+ @workflow_id = workflow_id
25
+ @run_id = run_id
26
+ end
27
+
28
+ def to_s
29
+ parts = [namespace, activity_id, workflow_id, run_id]
30
+ Base64.urlsafe_encode64(parts.join(SEPARATOR)).freeze
31
+ end
32
+ end
33
+ end
34
+ end