Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How to Debug a Cron Job That Silently Skips Its DST Run

说明与用途

cron 任务在夏令时转换期间跳过或重复运行。解决方案包括确认时区、添加幂等性、避免 1-3 AM 窗口并编写回归测试。

问题

A cron job scheduled at 2:30 AM local time runs reliably most of the year but twice a year either skips or runs twice due to daylight‑saving‑time transitions.

结果

The job now runs once per day, with idempotent safeguards, clear documentation, and automated tests ensuring correct behavior across DST transitions.

工作流

  • Confirm cron interprets schedules in local time, not UTC.
  • Identify whether the issue occurs during spring‑forward or fall‑back by checking logs and DST transition dates.
  • Read the scheduler’s documentation on DST behavior to understand its default handling.
  • Add idempotency to the job to guard against duplicate runs during fall‑back.
  • Avoid scheduling critical jobs inside the 1:00‑3:00 AM window; move them to a safer time like 5:00 AM.
  • Write regression tests that simulate the transition dates and assert exactly one run.
  • Document the chosen behavior next to the cron configuration for future engineers.

证据

A recurring job scheduled for 2:30 AM local time runs reliably for months, then twice a year it either doesn't run at all or runs twice back to back.

来源

Spring-forward (an hour skips, e.g., 2:00 AM jumps straight to 3:00 AM) and fall-back (an hour repeats, 1:00-2:00 AM happens twice) produce different symptoms.

来源

  • 记录日期: 2026-09-12T20:30:58.709Z