Sub topic 5
Schedule-based triggers
A schedule-based trigger starts the retraining pipeline on a clock, for example every Monday at 03:00 UTC. It does not look at drift, accuracy, or data volume. This chapter assumes you know how to run a training script, read a cron expression, and use a CI system such as GitHub Actions. Later chapters cover the signal-based triggers and how to combine them.
Why a clock is still a good trigger
Schedules are the easiest trigger to build and to reason about. They have three properties that signal-based triggers lack:
- They need no labels. Performance triggers wait for ground truth, which may arrive weeks late. A schedule works from day one.
- They are predictable. Compute budgets, on-call coverage, and downstream consumers can plan around a known cadence.
- They bound model age. If a drift detector fails silently, a schedule still refreshes the model. For this reason the trigger policy in the spine uses a
max_model_ageas a backstop.
The cost is waste and lag. A schedule retrains when nothing has changed, and it waits when something has. A weekly job cannot react to a shift that happens on Tuesday.
Choosing a cadence
Pick the interval from constraints, not habit.
| Factor | Effect on the interval |
|---|---|
| How fast the world changes (prices, fraud tactics) | Faster change means a shorter interval |
| Label delay | The interval should not be much shorter than the delay, or each run trains mostly on unlabeled recent data |
| New data per interval | Too little data gives a noisy challenger that rarely beats the champion |
| Training cost | Cost per run times runs per month must fit the budget |
| Pipeline runtime | The interval must be clearly longer than the longest run |
| Deployment risk | Each promotion is a change that can fail, so more runs mean more exposure |
A practical method is to measure how fast quality decays. Replay historical data: train at time T, then score each following week. The point where the metric loses more than your tolerance gives an upper bound on the interval. Retrain somewhat more often than that bound.
Align the schedule with known seasonality. A retail model should have a fresh version before a holiday peak, so add a manual or one-off run ahead of it rather than depending on the regular cadence.
A minimal scheduled workflow
The workflow below runs every Monday at 03:00 UTC. It also has a manual trigger, so an engineer can start a run on demand. I added two guards: a concurrency group so two runs never overlap, and a job timeout.
name: retrain
on:
schedule:
- cron: "0 3 * * 1"
workflow_dispatch: {}
concurrency:
group: retrain
cancel-in-progress: false
jobs:
retrain:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
- run: python -m pip install -r requirements.txt
- run: python train_pipeline.pyKnow these platform details before relying on it:
- Cron times in GitHub Actions are in UTC.
- Scheduled workflows run only from the default branch.
- Runs can start late when the platform is busy, so do not assume the job starts exactly at 03:00.
- In public repositories, scheduled workflows are disabled after 60 days without repository activity. A silently disabled schedule is a real failure mode.
Make a scheduled run reproducible
A common bug is computing the training window from the wall clock inside the job. If the run is delayed or retried, it trains on a different window than intended. Derive the window from the scheduled (logical) time instead, and leave a gap for label delay.
from datetime import datetime, timedelta, timezone
def training_window(scheduled_for, lookback_days=90, label_delay_days=7):
"""Return (start, end) for a run, based on its scheduled time.
The window ends label_delay_days before the schedule so that
labels for the newest rows have had time to arrive.
"""
end = scheduled_for.replace(hour=0, minute=0, second=0, microsecond=0)
end -= timedelta(days=label_delay_days)
start = end - timedelta(days=lookback_days)
return start, end
start, end = training_window(datetime(2026, 11, 30, 3, tzinfo=timezone.utc))
print(start.isoformat(), end.isoformat())For the run scheduled on 2026-11-30, this prints a window from 2026-08-25 to 2026-11-23. Rerunning the job a day later gives the same window, so the result is repeatable and the dataset version can be recorded in lineage.
Where the schedule sits in the pipeline
A scheduled firing is only a request to retrain. Checks before and after decide whether it has any effect.
The last branch matters most. A scheduled run that produces a worse model should end with the champion unchanged. The evaluation gate, covered in a later chapter, makes a routine schedule safe, because most runs will not justify a deployment.
Failure modes
- Overlapping runs. A run that takes longer than the interval starts a second one. Use a concurrency lock and a timeout, and alert when a run is skipped.
- Training on incomplete data. An upstream table that lands late gives a partial window. Run data validation first and abort on missing partitions rather than training on what exists.
- Retraining on corrupted data. A schedule retrains unconditionally, so a bad upstream change gets learned automatically. Validation and the gate are the defenses.
- Unnecessary deployments. If every run promotes a new model with a tiny difference, you add deployment risk with no benefit. Require a minimum gain.
- Synchronized load. Many teams scheduling at midnight compete for the same cluster. Pick an off-peak, non-round time, and add random delay if you run many models.
- Silent disablement. A job that stops running produces no error. Alert when the age of the production model exceeds the expected interval plus a margin.
When to prefer a schedule
Use a schedule as the primary trigger when labels are slow or absent, change is gradual, and training is cheap. Use it as a backstop when you rely on drift or performance signals. Avoid it as the only trigger when the data can shift abruptly or when each training run is expensive.
Exercise
A fraud model has a label delay of 30 days. Your team proposes a nightly scheduled retrain on the most recent 14 days of data. Give two problems with this plan and one change for each.
Show answer
First, the newest 14 days have mostly no labels yet, because labels arrive after 30 days, so the model trains on unlabeled or wrongly labeled rows. Fix it by ending the training window about 30 days before the scheduled time, using a function like trainingwindow with labeldelay_days=30. Second, a nightly cadence produces nearly identical training sets and many tiny, noisy challengers, which adds cost and deployment risk. Lengthen the interval (for example weekly), enlarge the lookback window, and require a minimum gain in the evaluation gate before promotion.