Ruby SDK

Runnables

Runnables in the Hatchet Ruby SDK are things that can be run, namely tasks and workflows. The two main types of runnables you'll encounter are:

  • Hatchet::Workflow, which lets you define tasks and call all of the run, schedule, etc. methods
  • Hatchet::Task, which is a single task returned by hatchet.task (standalone) or workflow.task, and can be run, scheduled, etc.

Triggering methods that don't wait for a result return run references - WorkflowRunRef and TaskRunRef - which are also documented below.

Workflow

Represents a workflow definition with one or more tasks arranged in a DAG.

wf = hatchet.workflow(name: "MyWorkflow")
step1 = wf.task(:step1) { |input, ctx| { "value" => 42 } }
wf.task(:step2, parents: [step1]) { |input, ctx|
  { "result" => ctx.task_output(step1)["value"] + 1 }
}

Methods

NameDescription
taskDefine a task within this workflow.
durable_taskDefine a durable task within this workflow.
batch_taskDefine a batch task within this workflow.
on_failure_taskDefine an on_failure task for this workflow.
on_success_taskDefine an on_success task for this workflow.
runRun this workflow synchronously and wait for it to complete.
run_no_waitTrigger a workflow run without waiting for it to complete.
run_manyRun this workflow in bulk and wait for all runs to complete.
run_many_no_waitRun this workflow in bulk without waiting for the runs to complete.
create_bulk_run_itemCreate a bulk run item for this workflow, intended to be used with the run_many methods.
scheduleSchedule this workflow to run at a specific time.
create_cronCreate a cron trigger for this workflow.

Attributes

client

The Hatchet client.

Returns:

TypeDescription
Hatchet::Client | nilThe Hatchet client.

concurrency

Workflow-level concurrency.

Returns:

TypeDescription
Array<ConcurrencyExpression> | ConcurrencyExpression | nilWorkflow-level concurrency.

default_filters

Default filters for event triggers.

Returns:

TypeDescription
Array<DefaultFilter>Default filters for event triggers.

default_priority

Default priority for runs (1-4)

Returns:

TypeDescription
Integer | nilDefault priority for runs (1-4)

id

Get the workflow ID (UUID). If not already set, lazily resolves it by looking up the workflow by name via the REST API.

Returns:

TypeDescription
String | nilThe workflow UUID.

idempotency

Idempotency configuration.

Returns:

TypeDescription
Hatchet::TTLBasedIdempotencyConfig | Hatchet::StatusBasedIdempotencyConfig | nilIdempotency configuration.

name

Workflow name.

Returns:

TypeDescription
StringWorkflow name.

on_crons

Cron expressions that trigger this workflow.

Returns:

TypeDescription
Array<String>Cron expressions that trigger this workflow.

on_events

Event keys that trigger this workflow.

Returns:

TypeDescription
Array<String>Event keys that trigger this workflow.

on_failure

The on_failure task.

Returns:

TypeDescription
Task | nilThe on_failure task.

on_success

The on_success task.

Returns:

TypeDescription
Task | nilThe on_success task.

sticky

Sticky strategy (:soft, :hard)

Returns:

TypeDescription
Symbol | nilSticky strategy (:soft, :hard)

task_defaults

Default task settings.

Returns:

TypeDescription
Hash | nilDefault task settings.

tasks

Map of task name to Task object.

Returns:

TypeDescription
Hash<Symbol, Task>Map of task name to Task object.

Functions

task

Define a task within this workflow. The block receives the workflow input and a Context object, and its return value (a Hash) becomes the task output.

Parameters:

NameTypeDescriptionDefault
nameSymbol | StringThe name of the task.required
parentsArray<Task, Symbol>A list of tasks that are parents of the task. Note: parents must be defined before their children.[]
execution_timeoutInteger | String | nilThe maximum time to wait for the task to complete, in seconds or as a duration string (e.g. "60s")nil
schedule_timeoutInteger | String | nilThe maximum time to wait for the task to be scheduled.nil
retriesInteger | nilThe number of times to retry the task before failing.nil
backoff_factorFloat | nilThe backoff factor for controlling exponential backoff in retries.nil
backoff_max_secondsInteger | nilThe maximum number of seconds to allow retries with exponential backoff to continue.nil
rate_limitsArray<RateLimit>A list of rate limit configurations for the task.[]
concurrencyConcurrencyExpression | Array<ConcurrencyExpression> | nilA concurrency expression (or list of them) controlling the concurrency settings for this task.nil
desired_worker_labelsHash | nilA hash of desired worker labels that determine to which worker the task should be assigned.nil
wait_forArrayA list of conditions that must be met before the task can run.[]
skip_ifArrayA list of conditions that, if met, will cause the task to be skipped.[]
depsHash | nilDependency providers to inject into the task's context.nil

Returns:

TypeDescription
TaskThe created task.

durable_task

Define a durable task within this workflow.

Parameters:

NameTypeDescriptionDefault
nameSymbol | StringTask name.required
eviction_policyHatchet::EvictionPolicy | nilEviction policy for this durable task. Defaults to Hatchet::DEFAULT_DURABLE_TASK_EVICTION_POLICY (15-minute TTL, capacity-eviction enabled). Pass nil to disable eviction entirely for this task.Hatchet::DEFAULT_DURABLE_TASK_EVICTION_POLICY
**optsHashOther Task options forwarded to task.{}

Returns:

TypeDescription
TaskThe created durable task.

batch_task

Define a batch task within this workflow.

Batch tasks buffer concurrent runs until Hatchet flushes the batch (size reached or flush interval), then invoke the block once with all buffered inputs keyed by each run's task-run external id. The block must return a Hash mapping each id to its output, or use broadcast_output on the batch config to return the same result to all callers. retries is always forced to 0 for batch tasks.

Preview: batch tasks are in beta and may change in future releases.

Parameters:

NameTypeDescriptionDefault
nameSymbol | StringTask name.required
batchHatchet::BatchTaskConfigBatch configuration.required
**optsHashOther Task options forwarded to task.{}

Returns:

TypeDescription
TaskThe created batch task.

on_failure_task

Define an on_failure task for this workflow.

Parameters:

NameTypeDescriptionDefault
**optsHashTask options.{}

Returns:

TypeDescription
Task

on_success_task

Define an on_success task for this workflow.

Parameters:

NameTypeDescriptionDefault
**optsHashTask options.{}

Returns:

TypeDescription
Task

run

Run this workflow synchronously and wait for it to complete.

Parameters:

NameTypeDescriptionDefault
inputHashThe input data for the workflow.{}
optionsTriggerWorkflowOptions | nilAdditional options for workflow execution, such as additional_metadata: and priority:.nil

Returns:

TypeDescription
HashThe workflow run output, keyed by task name (e.g. {"step1" => {...}, "step2" => {...}})

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.
Hatchet::FailedRunErrorIf the workflow run failed.

run_no_wait

Trigger a workflow run without waiting for it to complete. Useful for starting a run and immediately returning a reference to it without blocking while the workflow runs.

Parameters:

NameTypeDescriptionDefault
inputHashThe input data for the workflow.{}
optionsTriggerWorkflowOptions | nilAdditional options for workflow execution.nil

Returns:

TypeDescription
WorkflowRunRefA reference to the workflow run, whose result method blocks until the run completes.

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.

run_many

Run this workflow in bulk and wait for all runs to complete. Runs are triggered via bulk gRPC triggering (batched by 1000) and results are collected concurrently.

Parameters:

NameTypeDescriptionDefault
itemsArray<Hash>A list of bulk run items, as created by create_bulk_run_item.required
return_exceptionsBooleanIf true, exceptions are returned as part of the results instead of being raised.false

Returns:

TypeDescription
ArrayA list of results for each workflow run.

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.

run_many_no_wait

Run this workflow in bulk without waiting for the runs to complete.

Parameters:

NameTypeDescriptionDefault
itemsArray<Hash>A list of bulk run items, as created by create_bulk_run_item.required

Returns:

TypeDescription
Array<WorkflowRunRef>A list of references to the triggered workflow runs.

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.

create_bulk_run_item

Create a bulk run item for this workflow, intended to be used with the run_many methods.

Parameters:

NameTypeDescriptionDefault
inputHashThe input data for the workflow.{}
keyString | nilThe key for the workflow run, used for identification and deduplication.nil
optionsTriggerWorkflowOptions | nilAdditional options for the workflow run.nil

Returns:

TypeDescription
HashA bulk run item that can be passed to the run_many methods.

schedule

Schedule this workflow to run at a specific time.

Parameters:

NameTypeDescriptionDefault
timeTimeWhen to execute the workflow.required
inputHashThe input data for the workflow.{}
optionsScheduleTriggerWorkflowOptions | nilAdditional schedule options.nil

Returns:

TypeDescription
ObjectThe schedule response from the Hatchet engine.

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.

create_cron

Create a cron trigger for this workflow.

Parameters:

NameTypeDescriptionDefault
cron_nameStringThe name of the cron job.required
expressionStringThe cron expression that defines the schedule.required
inputHashThe input data for the workflow.{}

Returns:

TypeDescription
ObjectThe created cron workflow trigger.

Raises:

TypeDescription
Hatchet::ErrorIf no client is associated with the workflow.

Task

Represents a task within a workflow (or a standalone task).

Tasks are the basic unit of work in Hatchet. They can be defined as part of a workflow or as standalone tasks. Each task has a block that executes the task logic, receiving the workflow input and a context object.

step1 = workflow.task(:step1) { |input, ctx| { "result" => "done" } }
task = hatchet.task(name: "my_task") { |input, ctx| { "result" => "done" } }

Methods

NameDescription
runRun this task (or its owning workflow) synchronously.
run_no_waitRun this task without waiting for the result.
run_manyRun many instances of this task in bulk.
run_many_no_waitRun many instances without waiting for results.
create_bulk_run_itemCreate a bulk run item for use with run_many.
mock_runExecute task in unit test mode with mocked context.
id

Attributes

backoff_factor

Backoff factor between retries.

Returns:

TypeDescription
Float | nilBackoff factor between retries.

backoff_max_seconds

Maximum backoff seconds between retries.

Returns:

TypeDescription
Integer | nilMaximum backoff seconds between retries.

batch

Batch configuration, if this is a batch task.

Returns:

TypeDescription
Hatchet::BatchTaskConfig | nilBatch configuration, if this is a batch task.

client

The Hatchet client.

Returns:

TypeDescription
Hatchet::Client | nilThe Hatchet client.

concurrency

Task-level concurrency.

Returns:

TypeDescription
Array<ConcurrencyExpression> | ConcurrencyExpression | nilTask-level concurrency.

deps

Dependency providers.

Returns:

TypeDescription
Hash | nilDependency providers.

desired_worker_labels

Desired worker labels for scheduling.

Returns:

TypeDescription
Hash | nilDesired worker labels for scheduling.

durable

Whether this is a durable task.

Returns:

TypeDescription
BooleanWhether this is a durable task.

eviction_policy

Eviction policy for durable tasks.

Returns:

TypeDescription
Hatchet::EvictionPolicy | nilEviction policy for durable tasks.

execution_timeout

Execution timeout in seconds.

Returns:

TypeDescription
Integer | nilExecution timeout in seconds.

name

Task name.

Returns:

TypeDescription
Symbol | StringTask name.

parents

Parent task references.

Returns:

TypeDescription
Array<Task, Symbol>Parent task references.

rate_limits

Rate limits applied to this task.

Returns:

TypeDescription
Array<RateLimit>Rate limits applied to this task.

retries

Maximum number of retries.

Returns:

TypeDescription
Integer | nilMaximum number of retries.

schedule_timeout

Schedule timeout in seconds.

Returns:

TypeDescription
Integer | nilSchedule timeout in seconds.

skip_if

Skip-if conditions.

Returns:

TypeDescription
ArraySkip-if conditions.

wait_for

Wait-for conditions.

Returns:

TypeDescription
ArrayWait-for conditions.

workflow

The owning workflow.

Returns:

TypeDescription
Workflow | nilThe owning workflow.

Functions

run

Run this task (or its owning workflow) synchronously.

For standalone tasks the result is automatically unwrapped so that the caller receives the task output directly (e.g. {"result" => "done"}) rather than the workflow-level output keyed by task name (e.g. {"my_task" => {"result" => "done"}}).

Parameters:

NameTypeDescriptionDefault
inputHashInput data.{}
optionsTriggerWorkflowOptions | nilTrigger options.nil

Returns:

TypeDescription
HashThe task output.

run_no_wait

Run this task without waiting for the result.

Returns a TaskRunRef whose result method automatically unwraps the task output, matching the behaviour of run.

Parameters:

NameTypeDescriptionDefault
inputHashInput data.{}
optionsTriggerWorkflowOptions | nilTrigger options.nil

Returns:

TypeDescription
TaskRunRef

run_many

Run many instances of this task in bulk.

Parameters:

NameTypeDescriptionDefault
itemsArray<Hash>Bulk run items.required
return_exceptionsBooleanWhether to return exceptions instead of raising.false

Returns:

TypeDescription
ArrayResults (each unwrapped to the task output)

run_many_no_wait

Run many instances without waiting for results.

Parameters:

NameTypeDescriptionDefault
itemsArray<Hash>Bulk run items.required

Returns:

TypeDescription
Array<TaskRunRef>

create_bulk_run_item

Create a bulk run item for use with run_many.

Parameters:

NameTypeDescriptionDefault
inputHashInput data.{}
keyString | nilDeduplication key.nil
optionsTriggerWorkflowOptions | nilTrigger options.nil

Returns:

TypeDescription
HashBulk run item.

mock_run

Execute task in unit test mode with mocked context.

Parameters:

NameTypeDescriptionDefault
inputHashTask input.required
additional_metadataHashMetadata for the context.{}
retry_countIntegerSimulated retry count.0
parent_outputsHashMocked parent task outputs.{}

Returns:

TypeDescription
ObjectTask output.

id

Returns:

TypeDescription
StringThe workflow ID (for API calls)

WorkflowRunRef

Reference to a running workflow, returned by Workflow#run_no_wait.

The result is the full workflow-level output keyed by task readable_id, e.g. {"step1" => {...}, "step2" => {...}}.

ref = workflow.run_no_wait(input)
result = ref.result  # blocks until complete

Methods

NameDescription
resultBlock until the workflow run completes and return the result.

Attributes

workflow_run_id

The workflow run ID.

Returns:

TypeDescription
StringThe workflow run ID.

Functions

result

Block until the workflow run completes and return the result.

Uses the pooled gRPC SubscribeToWorkflowRuns listener when available. Falls back to gRPC GetRunDetails polling otherwise.

Returns:

TypeDescription
HashThe workflow run output keyed by task readable_id.

Raises:

TypeDescription
Hatchet::FailedRunErrorif the workflow run failed.

TaskRunRef

Reference to a running standalone task, returned by Task#run_no_wait.

Wraps a WorkflowRunRef and automatically extracts the task-specific output from the workflow-level result. For a task named "my_task", calling result returns the task output directly (e.g. {"value" => 42}) instead of the full keyed output ({"my_task" => {"value" => 42}}).

ref = my_task.run_no_wait(input)
output = ref.result  # => {"value" => 42}

Methods

NameDescription
resultBlock until the task completes and return the extracted task output.

Attributes

workflow_run_id

The workflow run ID.

Returns:

TypeDescription
StringThe workflow run ID.

Functions

result

Block until the task completes and return the extracted task output.

Returns:

TypeDescription
HashThe task output.

Raises:

TypeDescription
Hatchet::FailedRunErrorif the workflow run failed.

Last updated on August 24, 2026

On this page