logo

Cron Job

A cron job is a scheduled task that runs automatically at defined intervals. Named after the Unix cron daemon, it uses a specific syntax to define execution frequency and timing.

Cron Expression Syntax

┌───────── minute (0-59)
│ ┌───────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌───────── month (1-12)
│ │ │ │ ┌───────── day of week (0-7)
│ │ │ │ │
* * * * *

Examples

  • 0 9 * * * — Every day at 9:00 AM
  • */5 * * * * — Every 5 minutes
  • 0 0 * * 1 — Every Monday at midnight
  • 0 0 1 * * — First day of every month at midnight

Cron Jobs in Modern Applications

Traditional cron jobs run on a single server, which creates problems:

  • Single point of failure: If the server goes down, scheduled tasks stop
  • No retry logic: Failed tasks are simply lost
  • No visibility: No dashboard or logs for scheduled executions
  • Scaling issues: Can’t distribute across multiple machines

Managed Scheduling with AsyncQueue

AsyncQueue replaces traditional cron with a managed scheduling service:

  • Create scheduled tasks via API with cron expressions
  • Automatic execution with retry logic on failure
  • Full visibility into every execution in the dashboard
  • No servers to manage or monitor
await asyncqueue.tasks.create({
  callbackUrl: "https://api.example.com/daily-report",
  schedule: "0 9 * * *",  // Every day at 9 AM
  retries: 3
});