Schedules and background jobs

07·Concept·8 min

Not everything an app does starts with a click. Some work runs on a clock; some work is too slow to make a visitor wait for it.

Cron: work on a schedule

A cron job is a task that runs at set times. The schedule is written as five fields: minute, hour, day of month, month, day of week. A few to read:

  • 0 0 * * *: every day at midnight
  • 0 9 * * 1: every Monday at 9:00
  • */15 * * * *: every 15 minutes

The scheduler calls a path in your app (say, /api/send-digest) at those times. The app does the work when called; the scheduler only decides when. Times are in a fixed timezone, usually UTC, so 9:00 in Seoul is 0:00 UTC.

Queues: work in the background

When someone places an order, the receipt email should not delay the "thank you" page. The app puts a job on a queue and returns immediately. A worker picks the job up and sends the email seconds later.

Retries and idempotency

Background work fails sometimes: a mail server is busy, a network blips. Queues retry, usually with growing delays. That creates a new problem: a job that half-finished before failing will run again. Jobs must be idempotent, safe to run twice. "Send the receipt for order 42 if none has been sent" is safe; "send a receipt" is not.

Cron jobs need the same care. If a nightly run is late and the next one starts, both must not double-charge anyone.

Where DontCode fits

Insight Projects have a Scheduled jobs page, so you never write those five fields yourself. Say what should happen in plain words and pick when (every day, weekdays, every Monday, the 2nd of the month) in your own time zone; DontCode turns that into UTC cron, and the raw cron is still there under Advanced. Describing a job in the chat works too.

Save rebuilds your live app, so the list never saves on its own. Build has Insight write the code for that job; editing what should happen later shows Update code, which rewrites only that job.

The platform calls each job on time and authenticates the call. It does not retry a failed run, which is one more reason to make jobs idempotent. Plans cap how many jobs you can schedule and how many runs you get per month.

Insight builds themselves run as background jobs, which is why the History page shows progress instead of making you wait on a spinner.

Check your understanding

  1. 1.When does `0 9 * * 1` run?

  2. 2.Why send the receipt email from a background job instead of during checkout?

  3. 3.A job "charge the customer 10,000 won" fails after charging but before recording it, then retries. What went wrong in its design?

  4. 4.A schedule set to 9:00 runs at 18:00 in Seoul. Most likely reason?