Durable Timers - Ruby SDK
This page describes how to set a Durable Timer using the Temporal Ruby SDK.
A Durable Timer is used to pause the execution of a Workflow for a specified duration. A Workflow can sleep for days or even months. Timers are persisted, so even if your Worker or Temporal Service is down when the time period completes, as soon as your Worker and Temporal Service are back up, the Durable Timer call will resolve and your code will continue executing.
Sleeping is a resource-light operation: it does not tie up the process, and you can run millions of Timers off a single Worker.
To add a Timer in a Workflow, use Temporalio::Workflow.sleep
.
Technically Kernel#sleep
works, but the workflow form allows one to set a summary to view in the UI.
# Sleep for 72 hours
Temporalio::Workflow.sleep(72 * 60 * 60, summary: 'my timer')
There is also a Temporalio::Workflow.timeout
method that accepts a block and works like standard Ruby
Timeout.timeout
if needing the ability to timeout a set of code.