-
Notifications
You must be signed in to change notification settings - Fork 30
π₯ Standalone Activities for Ruby #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b1c199a
30ae677
411220b
0561236
8b3e08b
79ec0e8
aea6eb6
029e387
96bd69c
6c463ff
785f99a
ff172a9
3a76877
4978bde
a134674
7e679eb
2432134
85ae01f
54ea93e
4430429
b1540a0
3aefd55
346da6d
553ad50
404674a
1823197
35931d7
b7bc32b
b8b960d
c677537
9de8b3d
b496fb8
fc15980
3887a4e
cdd4ee9
cf6ae35
ccbd9ef
35f774b
e710c58
72f4233
5046a13
4a110b2
50834b1
f93c2f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CHANGELOG.md merge=union |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Changelog | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - π₯ Standalone Activities: activities that execute independently of any workflow. | ||
| ``` | ||
| handle = client.start_activity( | ||
| MyActivity, | ||
| 'some-arg', | ||
| id: 'my-activity-id', | ||
| task_queue: 'my-task-queue', | ||
| start_to_close_timeout: 60 | ||
| ) | ||
| result = handle.result # blocks until the activity completes | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1092,6 +1092,66 @@ it will raise the error raised in the activity. | |||||
| The constructor of the environment has multiple keyword arguments that can be set to affect the activity context for the | ||||||
| activity. | ||||||
|
|
||||||
| #### Standalone Activities | ||||||
|
|
||||||
| Activities can be started directly from a client, outside the context of any workflow. Standalone activities reuse the | ||||||
| existing `Activity::Definition` class β the same activity code runs whether invoked from a workflow or as a standalone | ||||||
| activity. They are addressed by `activity_id` (with an optional `activity_run_id` for disambiguating re-runs). | ||||||
|
|
||||||
| Start a standalone activity: | ||||||
|
|
||||||
| ```ruby | ||||||
| handle = client.start_activity( | ||||||
| MyActivity, | ||||||
| 'some-arg', | ||||||
| id: 'my-activity-id', | ||||||
| task_queue: 'my-task-queue', | ||||||
| start_to_close_timeout: 60 | ||||||
| ) | ||||||
| result = handle.result # blocks until the activity completes | ||||||
| ``` | ||||||
|
|
||||||
| Or use the start-and-wait shortcut: | ||||||
|
GregoryTravis marked this conversation as resolved.
|
||||||
|
|
||||||
| ```ruby | ||||||
| result = client.execute_activity( | ||||||
| MyActivity, 'some-arg', | ||||||
| id: 'my-activity-id', task_queue: 'my-task-queue', start_to_close_timeout: 60 | ||||||
| ) | ||||||
| ``` | ||||||
|
|
||||||
| Get a handle to an existing standalone activity to describe, cancel, terminate, or fetch its result: | ||||||
|
|
||||||
| ```ruby | ||||||
| handle = client.activity_handle('my-activity-id') | ||||||
| description = handle.describe # ActivityExecution::Description | ||||||
| result = handle.result # blocks until the activity reaches a terminal state | ||||||
| handle.cancel('reason for cancel'). # or | ||||||
|
|
||||||
| handle.terminate('reason for terminate') | ||||||
| ``` | ||||||
|
|
||||||
| List and count standalone activities (visibility queries): | ||||||
|
|
||||||
| ```ruby | ||||||
| client.list_activities('ActivityType="MyActivity"').each { |exec| puts exec.activity_id } | ||||||
| count = client.count_activities('ActivityType="MyActivity"').count | ||||||
| ``` | ||||||
|
|
||||||
| Inside an activity body, `Temporalio::Activity::Context.current.info` exposes whether the activity is standalone | ||||||
| or workflow-scheduled: | ||||||
|
|
||||||
| ```ruby | ||||||
| info = Temporalio::Activity::Context.current.info | ||||||
| if info.in_workflow? | ||||||
| # info.workflow_id, info.workflow_run_id, info.workflow_type are set | ||||||
| else | ||||||
| # info.activity_run_id is set; workflow_* fields are nil | ||||||
| end | ||||||
| ``` | ||||||
|
|
||||||
| Standalone activities require the dev server to enable the SAA feature flags. See the test bootstrap in | ||||||
| `temporalio/test/test.rb` for the required `--dynamic-config-value` flags. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us just be explicit here instead of referencing a file that might become stale.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These flags are not needed anymore (as of CLI 1.7.0). |
||||||
|
|
||||||
| ### Telemetry | ||||||
|
|
||||||
| #### Metrics | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,11 +7,13 @@ module Temporalio | |||||||||||
| module Activity | ||||||||||||
| Info = Data.define( | ||||||||||||
| :activity_id, | ||||||||||||
| :activity_run_id, | ||||||||||||
| :activity_type, | ||||||||||||
| :attempt, | ||||||||||||
| :current_attempt_scheduled_time, | ||||||||||||
| :heartbeat_timeout, | ||||||||||||
| :local?, | ||||||||||||
| :namespace, | ||||||||||||
| :priority, | ||||||||||||
| :retry_policy, | ||||||||||||
| :raw_heartbeat_details, | ||||||||||||
|
|
@@ -31,16 +33,21 @@ module Activity | |||||||||||
| # | ||||||||||||
| # @!attribute activity_id | ||||||||||||
| # @return [String] ID for the activity. | ||||||||||||
| # @!attribute activity_run_id | ||||||||||||
| # @return [String, nil] Run ID for a standalone activity execution. nil for activities scheduled from a workflow. | ||||||||||||
| # @!attribute activity_type | ||||||||||||
| # @return [String] Type name for the activity. | ||||||||||||
| # @!attribute attempt | ||||||||||||
| # @return [Integer] Attempt the activity is on. | ||||||||||||
| # @return [Integer] Attempt the activity is on. Attempts start at 1 and increment on each retry. | ||||||||||||
| # @!attribute current_attempt_scheduled_time | ||||||||||||
| # @return [Time] When the current attempt was scheduled. | ||||||||||||
| # @!attribute heartbeat_timeout | ||||||||||||
| # @return [Float, nil] Heartbeat timeout set by the caller. | ||||||||||||
| # @!attribute local? | ||||||||||||
| # @return [Boolean] Whether the activity is a local activity or not. | ||||||||||||
| # @!attribute namespace | ||||||||||||
| # @return [String, nil] Namespace this activity is on. Always set, including for standalone activities. Prefer this | ||||||||||||
| # accessor over the deprecated {workflow_namespace}. | ||||||||||||
|
Comment on lines
+48
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We don't need to reference the other, deprecated attribute. |
||||||||||||
| # @!attribute priority | ||||||||||||
| # @return [Priority] The priority of this activity. | ||||||||||||
| # @!attribute retry_policy | ||||||||||||
|
|
@@ -64,17 +71,24 @@ module Activity | |||||||||||
| # @return [String] Task token uniquely identifying this activity. Note, this is a `ASCII-8BIT` encoded string, not | ||||||||||||
| # a `UTF-8` encoded string nor a valid UTF-8 string. | ||||||||||||
| # @!attribute workflow_id | ||||||||||||
| # @return [String] Workflow ID that started this activity. | ||||||||||||
| # @return [String, nil] Workflow ID that started this activity. nil for standalone activities. | ||||||||||||
| # @!attribute workflow_namespace | ||||||||||||
| # @return [String] Namespace this activity is on. | ||||||||||||
| # @return [String, nil] Namespace this activity is on. | ||||||||||||
| # @deprecated Use {#namespace} instead. The value is identical regardless of whether the activity is | ||||||||||||
| # standalone or scheduled from a workflow. | ||||||||||||
| # @!attribute workflow_run_id | ||||||||||||
| # @return [String] Workflow run ID that started this activity. | ||||||||||||
| # @return [String, nil] Workflow run ID that started this activity. nil for standalone activities. | ||||||||||||
| # @!attribute workflow_type | ||||||||||||
| # @return [String] Workflow type name that started this activity. | ||||||||||||
| # @return [String, nil] Workflow type name that started this activity. nil for standalone activities. | ||||||||||||
| # | ||||||||||||
| # @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate this | ||||||||||||
| # class or it may break in incompatible ways. | ||||||||||||
| class Info | ||||||||||||
| # @return [Boolean] True if this activity was scheduled by a workflow execution; false for standalone activities. | ||||||||||||
| def in_workflow? | ||||||||||||
| !workflow_id.nil? | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| # Convert raw heartbeat details into Ruby types. | ||||||||||||
| # | ||||||||||||
| # Note, this live-converts every invocation. | ||||||||||||
|
|
||||||||||||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we don't do code snippets in release notes. There should be 1-2 paragraphs of feature description and a link to documentation. Breaking changes should be described in a separate section. See release notes in other SDKs.