Workflow Basics - Ruby SDK
Develop a Workflow
Workflows are the fundamental unit of a Temporal Application, and it all starts with the development of a Workflow Definition.
In the Temporal Ruby SDK programming model, Workflows are defined as classes.
Have the Workflow class extend Temporalio::Workflow::Definition to define a Workflow.
The entrypoint is the execute method.
class MyWorkflow < Temporalio::Workflow::Definition
def execute(name)
Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 100
)
end
end
Temporal Workflows may have any number of custom parameters. However, we strongly recommend that hashes or objects are used as parameters, so that the object's individual fields may be altered without breaking the signature of the Workflow.
Workflow Logic Requirements
Temporal Workflows must be deterministic, which includes Ruby workflows. This means there are several things workflows cannot do such as:
- Perform IO (network, disk, stdio, etc)
- Access/alter external mutable state
- Do any threading
- Do anything using the system clock (e.g.
Time.Now) - Make any random calls
- Make any not-guaranteed-deterministic calls
To prevent illegal workflow calls, a call tracer is put on the workflow thread that raises an exception if any illegal calls are made. Which calls are illegal is configurable in the worker options.
Customize Workflow Type
Workflows have a Type that are referred to as the Workflow name.
The following examples demonstrate how to set a custom name for your Workflow Type.
You can customize the Workflow name with a custom name in a workflow_name class method call on the class.
The Workflow name defaults to the unqualified class name.
class MyWorkflow < Temporalio::Workflow::Definition
# Customize the name
workflow_name :MyDifferentWorkflowName
def execute(name)
Temporalio::Workflow.execute_activity(
MyActivity,
{ greeting: 'Hello', name: },
start_to_close_timeout: 100
)
end
end