Skip to content

Delayed Execution

Schedule tasks to run at a specific time in the future.

Basic Delay

Use run_at to schedule a task for later:

// Run in 1 hour
const runAt = new Date(Date.now() + 3600000);

await conductor.invoke(
  { name: "send-reminder" },
  { userId: "123", message: "Don't forget!" },
  { run_at: runAt }
);

The task won't execute until the specified time.

With Deduplication

Combine delayed execution with dedupe_key:

// Ensure only one reminder per event
await conductor.invoke(
  { name: "send-reminder" },
  { eventId: "evt-123" },
  {
    dedupe_key: `reminder-evt-123`,
    run_at: reminderTime,
  }
);

Invoking again before it runs replaces the payload and run_at of the pending execution instead of creating a second one. See Deduplication.

Cancellation

To cancel a delayed task, you need its execution ID:

const executionId = await conductor.invoke(
  { name: "delayed-task" },
  {},
  { run_at: new Date(Date.now() + 3600000) }
);

// Later: cancel it
await conductor.cancel(executionId);

See Cancellation for details.

What's Next?