I am new to Temporal.
I am building a webapp where users can pause/unpause workflow execution.
Is there a built in way to do this in temporal? E.g a single command to the scheduler?
Or do I need to implement this myself using “pause” checks within my flow?
To pause a scheduled activity would be more involved, the activity code would need to query the workflow and check if it should be running and fail, which get complicated when considering the retry policy.
The simplest version of pause would be to simply wait until the workflow is unpaused before scheduling the next activity.
import * as workflow from '@temporalio/workflow';
import type * as activities from './activities';
const pauseSignal = workflow.defineSignal<[boolean]>('pauseToggle');
const { foo, bar } = workflow.proxyActivities<typeof activities>({ /* options */ });
export async function myWorkflow() {
let paused = false;
workflow.setHandler(pauseSignal, (st) => { paused = st });
await workflow.condition(() => !paused);
await foo();
await workflow.condition(() => !paused);
await bar();
}
You can also implement this via interceptors and avoid leaking into workflow logic:
To expand on this, you could also set a query handler that reports whether the workflow is currently paused and pause child workflows and other workflow APIs.