Standalone Activities Feature Guide
Standalone Activities are Activities that run independently, without being orchestrated by a
Workflow. Instead of starting an Activity from within a Workflow Definition, you start a Standalone
Activity directly from a Temporalio::Client.
The way you write the Activity and register it with a Worker is identical to Workflow Activities. The only difference is that you execute a Standalone Activity directly from your Temporal Client.
New to Standalone Activities? Start with the Standalone Activities Quickstart.
This page covers the following:
- Start a Standalone Activity without waiting for the result
- Get a handle to an existing Standalone Activity
- Wait for the result of a Standalone Activity
- List Standalone Activities
- Count Standalone Activities
- Run Standalone Activities with Temporal Cloud
This documentation uses source code from the standalone_activity sample.
Start a Standalone Activity without waiting for the result
Starting a Standalone Activity means sending a request to the Temporal Server to durably enqueue your Activity job, without waiting for it to be executed by your Worker.
Use Temporalio::Client#start_activity to start a
Standalone Activity and get a handle without waiting for the result:
handle = client.start_activity(
StandaloneActivity::MyActivities::ComposeGreeting,
'Hello', 'World',
id: 'standalone-activity-id',
task_queue: 'standalone-activity-sample',
start_to_close_timeout: 10
)
puts "Started Activity with id=#{handle.id} run_id=#{handle.run_id}"
# Wait for the result later
puts "Activity result: #{handle.result}"
With the Temporal Server and Worker running, open a new terminal in the samples-ruby directory and
run:
bundle exec ruby standalone_activity/start_activity.rb
Or use the Temporal CLI:
temporal activity start \
--type ComposeGreeting \
--activity-id standalone-activity-id \
--task-queue standalone-activity-sample \
--start-to-close-timeout 10s \
--input '"Hello"' \
--input '"World"'
Get a handle to an existing Standalone Activity
Use Temporalio::Client#activity_handle to create an ActivityHandle for a previously started Standalone Activity:
handle = client.activity_handle('standalone-activity-id')
Pass no run ID (the default) to target the latest run of the given Activity ID, or pass
activity_run_id: to target a specific run. You can then use the handle to wait for the result,
describe, cancel, or terminate the Activity:
handle.result # block until the activity completes; returns the result
handle.describe # fetch metadata (status, timestamps, attempt, last failure, etc.)
handle.cancel # request cancellation
handle.terminate # force-close the activity
Wait for the result of a Standalone Activity
Under the hood, calling client.execute_activity is the same as calling client.start_activity to
durably enqueue the Standalone Activity, and then calling handle.result to block until the
Activity completes and return the result:
result = handle.result
Or use the Temporal CLI to wait for a result by Activity ID:
temporal activity result --activity-id standalone-activity-id
List Standalone Activities
Use Temporalio::Client#list_activities to list
Standalone Activity Executions that match a List Filter query. The result is an
Enumerator of ActivityExecution values that fetches pages from the server on demand as the
enumerator is consumed.
These APIs return only Standalone Activity Executions. Activities running inside Workflows are not included.
client.list_activities("TaskQueue = 'standalone-activity-sample'").each do |execution|
puts "#{execution.activity_id} #{execution.activity_type} #{execution.status}"
end
Run it:
bundle exec ruby standalone_activity/list_activities.rb
Or use the Temporal CLI:
temporal activity list
The query parameter accepts the same List Filter syntax used for Workflow
Visibility. For example, ActivityType = 'ComposeGreeting' AND Status = 'Running'.
Count Standalone Activities
Use Temporalio::Client#count_activities to count
Standalone Activity Executions that match a List Filter query. This returns the
total count of executions (running, completed, failed, etc.) — not the number of queued tasks. It
works the same way as counting Workflow Executions.
result = client.count_activities("TaskQueue = 'standalone-activity-sample'")
puts "Total: #{result.count}"
result.groups.each do |group|
puts " #{group.group_values.join(',')} => #{group.count}"
end
Run it:
bundle exec ruby standalone_activity/count_activities.rb
Or use the Temporal CLI:
temporal activity count
Run Standalone Activities with Temporal Cloud
The Worker and Client code in the Standalone Activities Quickstart
use Temporalio::EnvConfig::ClientConfig.load_client_connect_options,
so the same code works against Temporal Cloud — configure the connection via environment
variables or a TOML profile. No code changes are needed.
For a step-by-step guide on connecting to Temporal Cloud, including Namespace creation, certificate generation, and authentication setup in the Cloud UI, see Connect to Temporal Cloud.
Connect with mTLS
Set these environment variables with values from your Temporal Cloud Namespace settings:
export TEMPORAL_ADDRESS=<your-namespace>.<your-account-id>.tmprl.cloud:7233
export TEMPORAL_NAMESPACE=<your-namespace>.<your-account-id>
export TEMPORAL_TLS_CLIENT_CERT_PATH='path/to/your/client.pem'
export TEMPORAL_TLS_CLIENT_KEY_PATH='path/to/your/client.key'
Connect with an API key
Set these environment variables with values from your Temporal Cloud API key settings:
export TEMPORAL_ADDRESS=<your-namespace>.<your-account-id>.tmprl.cloud:7233
export TEMPORAL_NAMESPACE=<your-namespace>.<your-account-id>
export TEMPORAL_API_KEY=<your-api-key>
Then run the Worker and starter code as shown in the Standalone Activities Quickstart.