← All Learning Paths

Cron Jobs and Scheduling

Make scheduled work boring: idempotent handlers, distributed locks, leader election, heartbeats, clock-skew debugging, and cleanup jobs that respect retention rules.

technicalbeginner8 nodes21.67h total

Path overview

定时任务的危险之处在于平时正常、出错时在半夜。本路径围绕幂等与时钟两大主题,配齐分布式锁、领导者选举与心跳监控,再实战数据保留清理与两个完整项目,把夜间告警变成可控工程。

Scheduled jobs fail at 3 a.m. by design. This path centers idempotency and clocks, adds distributed locks, leader election, heartbeats, retention cleanup, and two complete projects.

  1. Use "Cron Expression Explainer" on a cron sample, then check "text to explanation" against your manual result.

    Completion criteria: Run two inputs through "Cron Expression Explainer", record both outputs, and show one case where "Parse a five-field cron expression and get a field-by-field plain-English explanation plus a" changes as expected.

    Next step: Inject a Clock Instead of Calling Date.now

    ⏱ 0.25h

  2. Run "Make time-dependent logic deterministic by injecting a clock and testing the exact boundary" from "Inject a Clock Instead of Calling Date.now" and confirm the documented result "Domain code accepts a Clock, and only the composition root passes systemClock.".

    Prerequisites: Cron Expression Explainer

    Completion criteria: Show the command for every step of "Inject a Clock Instead of Calling Date.now" and paste the output proving "Make time-dependent logic deterministic by injecting a clock and testing the exact boundary"; then note the step where "Domain code accepts a Clock, and only the composition root passes systemClock." appears.

    Next step: Monitor Cron Jobs with Dead-Man's-Switch Heartbeats

    ⏱ 0.5h

  3. Apply "Monitor Cron Jobs with Dead-Man's-Switch Heartbeats" to a cron task, checking that "HTTP 201 with a JSON object containing name nightly-billing-export, schedule 0 2 * * *," appears after the "Add success-only heartbeat pings to a scheduled PostgreSQL backup and configure a" step.

    Prerequisites: Inject a Clock Instead of Calling Date.now

    Completion criteria: Run "Monitor Cron Jobs with Dead-Man's-Switch Heartbeats" twice — once as written and once with a changed input — and attach both transcripts with the observed difference.

    Next step: Clean Up Expired Idempotency Keys

    ⏱ 0.5h

  4. Execute "Clean Up Expired Idempotency Keys" end to end, then repeat the last step with one parameter changed and compare "Keep the idempotency table small and fast without deleting keys that a client may still".

    Prerequisites: Monitor Cron Jobs with Dead-Man's-Switch Heartbeats

    Completion criteria: Run the steps through "Keep the idempotency table small and fast without deleting keys that a client may still", paste the command output, and mark the line that matches "The table is partitioned by day and the primary key includes created_at as required by"; then rerun with one parameter changed.

    Next step: Implement a Data Retention Cleanup

    ⏱ 0.5h

  5. Carry out "Implement a Data Retention Cleanup" on a cron project, pausing at the "Remove data that is no longer needed while proving that legal holds and required records are" step to verify "Every data class has a documented retention rule and an exception path.".

    Completion criteria: Produce a run log for "Implement a Data Retention Cleanup" that ends at "Remove data that is no longer needed while proving that legal holds and required records are" and mark every step where "Every data class has a documented retention rule and an exception path." was checked.

    Next step: Build a Cron Job Dashboard with Schedules and Run History

    ⏱ 1.5h

  6. Deliver the "Build a Cron Job Dashboard with Schedules and Run History" blueprint with "Job CRUD from the UI with cron expressions parsed and validated with a next-run preview" working and "A scheduler loop that fires due jobs and tolerates clock skew and missed intervals" recorded as evidence.

    Prerequisites: Implement a Data Retention Cleanup

    Completion criteria: Deliver "Job CRUD from the UI with cron expressions parsed and validated with a next-run preview" and paste the test output where the acceptance test passes; include the test name and command.

    Next step: Count Cron Runs Inside a Window

    ⏱ 7h

  7. In the "Cron Jobs and Scheduling" path, implement "Count Cron Runs Inside a Window" so JSON object: { cron: */N * * * * | M * * * *, from: ISO string, to: yields {count:4,firstRuns:[2026-01-01T00:00:00.000Z,2026-01-01T00:15:00.000Z,, including the second sample's edge case.

    Prerequisites: Build a Cron Job Dashboard with Schedules and Run History

    Completion criteria: Submit a solution for "Cron Jobs and Scheduling" that passes both samples ({cron:*/15 * * * *,from:2026-01-01T00:00:00Z,to:2026-01-01T0 to {count:4,firstRuns:[2026-01-01T00:00:00.000Z,2026-01-01T00:1) and attach the failing case you fixed.

    Next step: Build an Incremental Backup Tool with Snapshot Catalogs

    ⏱ 0.42h

  8. Ship "Content-defined chunking with a rolling hash boundary keeps chunk boundaries stable under" from "Build an Incremental Backup Tool with Snapshot Catalogs", then prove it with the project's test suite and an acceptance note.

    Prerequisites: Build a Cron Job Dashboard with Schedules and Run History, Count Cron Runs Inside a Window

    Completion criteria: Ship "Content-defined chunking with a rolling hash boundary keeps chunk boundaries stable under" and attach the test log plus a one-page acceptance note mapping the feature to the passing test.

    Next step: Apply this path in a capstone project and review the related resources.

    ⏱ 8h