DocsGuides

Workers & scheduled jobs

Run background tasks, queue consumers and cron jobs.

Guides 4 min read

Workers are services without a public URL. They are perfect for processing queues, sending emails, syncing data or running tasks on a schedule.

Long-running workers

A worker is simply a process that never exits. If it crashes, DIGITALYCloud restarts it automatically.

worker.js
async function loop() {
  while (true) {
    const job = await queue.next();
    if (job) await handle(job);
    else await new Promise((r) => setTimeout(r, 2000));
  }
}
loop();

Scheduled jobs

For tasks that run on a schedule, add a cron expression in the service settings. Your command runs, finishes, and the container stops until the next run.

ExpressionRuns
*/15 * * * *Every 15 minutes
0 3 * * *Every day at 03:00 (Europe/Paris)
0 9 * * 1Every Monday at 09:00

Before you schedule a job

  • Make sure the job can safely run twice (for example after a retry).
  • Exit with a non-zero code on failure so it shows as failed.
  • Log a short summary at the end of each run.
Was this article helpful?