Sub topic 5
Schedule-Based Triggers
Assume you understand the basic model lifecycle: training, validation, testing, and deployment. This chapter focuses on one question: when should an automated pipeline start retraining because time has passed?
A schedule-based trigger starts a retraining pipeline at fixed times, such as every Monday at 03:00 UTC. It is the simplest trigger to implement and gives the team predictable compute usage.
Choose a Cadence
The cadence is the time between scheduled runs. Choose it based on how quickly the problem changes and how costly retraining is.
| Use case | Possible cadence | Reason |
|---|---|---|
| Slowly changing demand forecast | Monthly | New patterns appear gradually |
| Fraud detection | Daily or weekly | Behavior can change quickly |
| Recommendation model | Several times per day | User preferences and inventory change often |
A shorter cadence does not automatically produce a better model. If new data is noisy, incomplete, or too similar to the previous training set, frequent retraining can add cost without improving predictions.
The schedule should also account for data availability. Starting training at 03:00 UTC is unsafe if the previous day's data is not complete until 04:00 UTC. Add a data-readiness check before training rather than assuming that the clock guarantees fresh data.
Model the Scheduled Run
A scheduled pipeline normally follows this sequence:
The pipeline should be idempotent, meaning that repeating the same run does not create conflicting results. Give each run a unique identifier based on its scheduled interval and input-data version. Before starting, check whether that interval has already completed.
Also define what happens when a run is missed. A temporary outage might cause the scheduler to skip a run. You can run it immediately after recovery, skip it because the next scheduled run is sufficient, or backfill the missed interval. The correct choice depends on whether each interval represents essential data.
Implement a Basic Schedule
GitHub Actions can start a training script every Monday and can also support a manual run:
name: retrain
on:
schedule:
- cron: "0 3 * * 1"
workflow_dispatch: {}
jobs:
retrain:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python -m pip install -r requirements.txt
- run: python train_pipeline.pyThe cron expression uses UTC. The workflow runs at minute 0, hour 3, on day 1 of each week. A manual trigger is useful for recovery, testing, and approved early retraining.
Exercise
Exercise
A model needs yesterday's complete data, which is usually available at 06:00 UTC. When should a daily schedule start, and what check should follow it?
Show answer
Start after 06:00 UTC, then check that the expected partition exists and passes data-readiness validation before training.