Quickstart
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.
This documentation uses source code from the standalone-activity sample.
Get started with Standalone Activities
Prerequisites:
-
Ruby 3.3+
-
Temporal Ruby SDK (v1.9.0 or higher). See the Ruby Quickstart for install instructions.
-
Temporal CLI v1.9.1 or higher. Install with Homebrew, or see the Temporal CLI install guide for other platforms. Verify the installation with
temporal --version.
Start the Temporal development server with temporal server start-dev.
This command automatically starts the Temporal development server with the Web UI, and creates the default Namespace.
It uses an in-memory database, so do not use it for real use cases.
The Temporal Server will now be available for client connections on localhost:7233, and the
Temporal Web UI will now be accessible at http://localhost:8233.
brew install temporal
temporal --version
temporal server start-dev
Clone the sample
Clone the documentation-sdk-code-examples repository, switch to the ruby-sandbox directory, and install the dependencies.
Run every command on this page from that directory.
git clone https://github.com/temporalio/documentation-sdk-code-examples.git
cd documentation-sdk-code-examples/ruby-sandbox
bundle install
The sample consists of separate programs in the activities/standalone-activity directory:
activities/standalone-activity/
├── my_activities.rb # Activity definition
├── worker.rb # Worker that processes activity tasks
└── execute_activity.rb # Starts an activity and waits for the result
Define your Activity
An Activity in the Temporal Ruby SDK is a subclass of Temporalio::Activity::Definition that
implements an execute method. The way you define a Standalone Activity is identical to how you
define an Activity orchestrated by a Workflow. In fact, the same Activity can be executed both as a
Standalone Activity and as a Workflow Activity.
require 'temporalio/activity'
module StandaloneActivity
module MyActivities
class ComposeGreeting < Temporalio::Activity::Definition
def execute(greeting, name)
"#{greeting}, #{name}!"
end
end
end
end
Run a Worker with the Activity registered
Running a Worker for Standalone Activities is the same as running a Worker for Workflow Activities —
you create a Temporalio::Worker, register the Activity class, and call worker.run. The Worker
doesn't need to know whether the Activity will be invoked from a Workflow or as a Standalone
Activity. See Run a Worker for more details on
Worker setup and configuration options.
activities/standalone-activity/worker.rb
Open a new terminal, switch to the ruby-sandbox directory, and run the Worker.
Leave this terminal running — the Worker needs to stay up to process activities.
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'
require_relative 'my_activities'
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233'
args[1] ||= 'default'
client = Temporalio::Client.connect(*args, **kwargs)
# A Worker for Standalone Activities is configured the same way as one for
# Workflow Activities. No Workflows are required.
worker = Temporalio::Worker.new(
client:,
task_queue: 'standalone-activity-sample',
activities: [StandaloneActivity::MyActivities::ComposeGreeting]
)
puts 'Starting worker (ctrl+c to exit)'
worker.run(shutdown_signals: ['SIGINT'])
bundle exec ruby activities/standalone-activity/worker.rb
Execute a Standalone Activity
Use Temporalio::Client#execute_activity to execute a
Standalone Activity and block until it completes. Call this from your application code, not from
inside a Workflow Definition. This durably enqueues your Standalone Activity in the Temporal Server,
waits for it to be executed on your Worker, and then returns the result.
activities/standalone-activity/execute_activity.rb
The first argument is the Activity to run. It can be the Activity::Definition subclass, an
instance of one, or a string/symbol name. Positional arguments after it are passed to the Activity's
execute method. The call requires id, task_queue, and at least one of start_to_close_timeout
or schedule_to_close_timeout.
To run it:
- Make sure the Temporal Server is running (from the Get Started step above).
- Make sure the Worker is running (from the Run a Worker step above).
- Open a new terminal, switch to the
ruby-sandboxdirectory, and run:bundle exec ruby activities/standalone-activity/execute_activity.rb
Or use the Temporal CLI.
You should see:
Activity result: Hello, World!
require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'my_activities'
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233'
args[1] ||= 'default'
client = Temporalio::Client.connect(*args, **kwargs)
result = client.execute_activity(
StandaloneActivity::MyActivities::ComposeGreeting,
'Hello', 'World',
id: 'standalone-activity-id',
task_queue: 'standalone-activity-sample',
start_to_close_timeout: 10
)
puts "Activity result: #{result}"
bundle exec ruby activities/standalone-activity/execute_activity.rb
temporal activity execute \
--type ComposeGreeting \
--activity-id standalone-activity-id \
--task-queue standalone-activity-sample \
--start-to-close-timeout 10s \
--input '"Hello"' \
--input '"World"'
Run with Temporal Cloud
All code samples on this page use
Temporalio::EnvConfig::ClientConfig.load_client_connect_options
to configure the Temporal Client connection. It responds to environment
variables and TOML configuration
files, so the same code works against a local dev
server and Temporal Cloud without changes. See Run Standalone Activities with Temporal
Cloud in the feature guide
for mTLS and API key setup.
Next steps
- Standalone Activities feature guide: Start without waiting, get handles, list and count Activities, and connect to Temporal Cloud.
- Activity basics: Write and register Activities with the Ruby SDK.