Ruby SDK

Hatchet Ruby SDK Reference

This is the Ruby SDK reference, documenting methods available for interacting with Hatchet resources. Check out the user guide for an introduction for getting your first tasks running.

The Hatchet Ruby Client

The main client for interacting with Hatchet services.

hatchet = Hatchet::Client.new()
hatchet = Hatchet::Client.new(
  token: "your-jwt-token",
  namespace: "production"
)
wf = hatchet.workflow(name: "MyWorkflow")
step1 = wf.task(:step1) { |input, ctx| { "result" => 42 } }
my_task = hatchet.task(name: "my_task") { |input, ctx| { "result" => "done" } }

The constructor accepts keyword options. Anything not passed explicitly is read from HATCHET_CLIENT_* environment variables.

Options:

NameTypeDescription
debugBooleanEnable debug logging (default: false)
tokenStringThe JWT token for authentication (required)
tenant_idStringOverride tenant ID (extracted from JWT token 'sub' field if not provided)
host_portStringgRPC server host and port (default: "localhost:7070")
server_urlStringServer URL for HTTP requests.
namespaceStringNamespace prefix for resource names (default: "")
loggerLoggerCustom logger instance.
worker_preset_labelsHashDefault labels applied to all workers.

Methods:

NameDescription
workerCreate a Hatchet worker on which to run workflows.
workflowDefine a Hatchet workflow, which can then declare tasks and be run, scheduled, and so on.
taskCreate a standalone Hatchet task.
durable_taskCreate a standalone durable Hatchet task, which works using Hatchet's durable execution capabilities.
batch_taskCreate a standalone batch task (auto-wraps in a single-task workflow).

Attributes

cel

The CEL client is a client for debugging CEL expressions within Hatchet. See the CEL client.

config

The configuration object used by this client.

cron

The cron client is a client for managing cron workflow triggers within Hatchet. See the Cron client.

events

The events client, which you can use to push events to Hatchet to trigger event-driven workflows. See the Events client.

filters

The filters client is a client for managing filters within Hatchet, which scope event triggers to workflows using CEL expressions. See the Filters client.

logger

Convenience accessor for the logger.

logs

The logs client is a client for interacting with Hatchet's logs API. See the Logs client.

metrics

The metrics client is a client for reading metrics out of Hatchet's metrics API. See the Metrics client.

rate_limits

The rate limits client is a wrapper for Hatchet's gRPC API that makes it easier to work with rate limits in Hatchet. See the Rate Limits client.

runs

The runs client is a client for interacting with task and workflow runs within Hatchet. See the Runs client.

scheduled

The scheduled client is a client for managing scheduled workflow runs within Hatchet. See the Scheduled client.

tenant

The tenant client is a client for reading information about the tenant you're operating in. See the Tenant client.

tenant_id

The tenant ID.

workers

The workers client is a client for managing workers programmatically within Hatchet. See the Workers client.

workflows

The workflows client is a client for managing workflow declarations programmatically within Hatchet. Note that workflows are the declaration, not the individual runs; if you're looking for runs, use the runs client instead. See the Workflows client.

Functions

worker

Create a Hatchet worker on which to run workflows.

worker = hatchet.worker("my-worker", workflows: [wf], slots: 10)
worker.start

Parameters:

NameTypeDescriptionDefault
nameStringThe name of the worker.required
workflowsArray<Workflow, Task>A list of workflows (or standalone tasks) to register on the worker.[]
slotsIntegerSlot count for standard tasks, i.e. the number of tasks the worker can run concurrently.10
durable_slotsInteger | nilSlot count for durable tasks; defaults to slots if not provided.nil
labelsHashA hash of labels to assign to the worker, for use with worker affinity; merged with the client's worker_preset_labels.{}

Returns:

TypeDescription
Hatchet::WorkerThe created worker object, which exposes an instance method start which can be called to start the worker (blocking until shutdown), and stop to request a graceful shutdown.

workflow

Define a Hatchet workflow, which can then declare tasks and be run, scheduled, and so on.

wf = hatchet.workflow(name: "MyWorkflow")
wf.task(:step1) { |input, ctx| { "value" => 42 } }

Parameters:

NameTypeDescriptionDefault
nameStringThe name of the workflow.required
on_eventsArray<String>A list of event triggers for the workflow - events which cause the workflow to be run.[]
on_cronsArray<String>A list of cron triggers for the workflow.[]
concurrencyConcurrencyExpression | Array<ConcurrencyExpression> | nilA concurrency object (or list of them) controlling the concurrency settings for this workflow.nil
default_priorityInteger | nilThe default priority of the workflow. Higher values will cause runs of this workflow to have priority in scheduling over other, lower priority ones.nil
task_defaultsHash | nilDefault task settings for this workflow.nil
default_filtersArray<DefaultFilter>A list of filters to create when the workflow is created.[]
stickySymbol | nilA sticky strategy for the workflow, either :soft or :hard.nil
idempotencyTTLBasedIdempotencyConfig | StatusBasedIdempotencyConfig | nilAn idempotency configuration for the workflow.nil

Returns:

TypeDescription
Hatchet::WorkflowThe created workflow object, which can be used to declare tasks, run the workflow, and so on.

task

Create a standalone Hatchet task. The task is automatically wrapped in a single-task workflow, so it can be run, scheduled, and registered on a worker just like a workflow. The block receives the run's input and a Context object.

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

Parameters:

NameTypeDescriptionDefault
nameStringThe name of the task.required
on_eventsArray<String>A list of event triggers for the task - events which cause the task to be run.[]
default_filtersArray<DefaultFilter>A list of filters to create when the task is created.[]
idempotencyTTLBasedIdempotencyConfig | StatusBasedIdempotencyConfig | nilAn idempotency configuration for the task.nil

Returns:

TypeDescription
Hatchet::TaskThe created task object, which can be run, scheduled, and registered on a worker.

durable_task

Create a standalone durable Hatchet task, which works using Hatchet's durable execution capabilities. Durable tasks receive a DurableContext with additional methods like sleep_for and wait_for.

Parameters:

NameTypeDescriptionDefault
nameStringThe name of the task.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
**optsHashAny other keyword arguments (retries:, execution_timeout:, and so on) are forwarded to the task declaration - see Workflow#task for the full list.{}

Returns:

TypeDescription
Hatchet::TaskThe created durable task object.

batch_task

Create a standalone batch task (auto-wraps in a single-task 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.

batch = hatchet.batch_task(name: "my_batch", batch: Hatchet::BatchTaskConfig.new(max_size: 3)) do |inputs, ctx|
  inputs.transform_values { |input| { "result" => input["message"].upcase } }
end

Parameters:

NameTypeDescriptionDefault
nameStringThe name of the task.required
batchHatchet::BatchTaskConfigThe batch configuration (max_size, flush interval, broadcast_output)required
**optsHashAny other keyword arguments (on_events:, idempotency:, and so on) are forwarded to task.{}

Returns:

TypeDescription
Hatchet::TaskThe created batch task object.

Last updated on August 24, 2026

On this page