Decide which jobs are due
Evaluate a schedule export deterministically without installing or running a scheduled task.
A scheduling decision can be a pure calculation
Before connecting a script to an operating system scheduler, you can test the decision it makes. This exercise reads supplied job records and a caller-provided current time. It returns whether each enabled job is due, should wait, or needs review. It does not launch any command or register a scheduled task.
For an interval schedule, the next due time is the last successful run plus the interval. A job becomes due when that time is equal to or earlier than now. This inclusive boundary differs from the strict age comparison used for stale backups, because these rules answer different questions.
Unknown history requires a defined policy
A missing or empty last-success value represents a job that has never completed, so this exercise marks it due with no calculated timestamp. A malformed, timezone-naive or future value is inconsistent evidence and needs review instead. Do not silently treat a timestamp from the future as a reason to wait indefinitely.
Validate positive whole-hour intervals, actual Boolean enabled flags and unique normalized names, including disabled records. Ignore disabled jobs only after validation. Sort returned records by name and express calculated times as UTC ISO strings ending in Z.
Passing time explicitly makes the result repeatable. A real scheduler also needs concurrency control, retry policy and monitoring, which are outside this file-based decision exercise.
from datetime import datetime, timedelta
last = datetime.fromisoformat("2026-11-17T08:00:00+00:00")
print((last + timedelta(hours=4)).isoformat())
Put it into practice.
Define job_decisions(jobs,now). Records have string name, Boolean enabled, positive integer interval_hours (not bool), and optional last_success. Normalize names with strip().casefold(); empty/duplicate names or invalid flags/intervals raise ValueError, including disabled jobs. now must be timezone-aware. Return enabled jobs sorted by name as name,decision,next_due. Missing/empty last_success means due with None. Invalid/naive/future last_success means review with None. Otherwise next_due is last_success + interval in UTC ISO format ending Z; decision is due when next_due <= now, otherwise wait. Do not execute jobs or mutate inputs.
See an explained solution
from datetime import datetime, timezone
def parse_utc(value):
moment = datetime.fromisoformat(value)
if moment.tzinfo is None or moment.utcoffset() is None:
raise ValueError("Timestamp needs an offset")
return moment.astimezone(timezone.utc)
from datetime import timedelta
def job_decisions(jobs, now):
current = parse_utc(now)
seen, results = set(), []
for job in jobs:
name = job["name"].strip().casefold()
hours = job["interval_hours"]
if not name or name in seen or type(hours) is not int or hours <= 0 or type(job["enabled"]) is not bool:
raise ValueError("Invalid or duplicate job")
seen.add(name)
if not job["enabled"]:
continue
last = job.get("last_success")
decision, due = "due", None
if last not in (None, ""):
try:
moment = parse_utc(last)
if moment > current:
raise ValueError("Future success")
due = moment + timedelta(hours=hours)
decision = "due" if due <= current else "wait"
except (TypeError, ValueError):
decision, due = "review", None
results.append({"name": name, "decision": decision,
"next_due": due.isoformat().replace("+00:00", "Z") if due else None})
return sorted(results, key=lambda row: row["name"])
if __name__ == "__main__":
print(job_decisions([{"name":"backup","enabled":True,"interval_hours":24}], "2026-11-17T12:00:00Z"))
The decision function separates schedule policy from execution. Missing history can trigger a first run, while inconsistent history remains a review item rather than a false healthy state.