Skip to content

Cron SLA Compliance — Service Level Agreements for Scheduled Jobs

DodaTech Updated 2026-06-28 7 min read

In this tutorial, you will learn about Cron SLA Compliance. We cover key concepts, practical examples, and best practices to help you master this topic.

Learn cron SLA compliance: define service level agreements for cron job execution, track service level indicators like execution timeliness, duration, and reliability, calculate uptime, and alert on SLA breaches.

What You Learn

You will learn how to define and monitor SLAs for Cron Jobs: setting SLI targets for timeliness, duration, and reliability, measuring compliance, calculating scheduled uptime, and reporting on SLA attainment.

Why It Matters

Without SLAs, cron job reliability is subjective. A daily backup that completes in 6 hours may be "fine" to the engineer but violates the 4-hour SLA. Defined SLAs make reliability measurable and create accountability.

Real-World Use

DodaTech has SLA tiers for cron jobs: Platinum (99.99% uptime, 1-hour completion, 5-minute delay), Gold (99.9%, 4-hour completion, 30-minute delay), Silver (99%, 8-hour completion, 2-hour delay). Monthly SLA reports are sent to service owners. Breaches trigger a post-mortem.

SLA Calculator

import time
from datetime import datetime, timedelta
import json

class CronSLA:
    def __init__(self, name, slo_pct=99.9, max_delay_minutes=30, max_duration_minutes=60):
        self.name = name
        self.slo = slo_pct
        self.max_delay = max_delay_minutes
        self.max_duration = max_duration_minutes
        self.executions = []

    def record(self, scheduled_time, actual_time, duration_minutes, success):
        delay = (actual_time - scheduled_time).total_seconds() / 60
        self.executions.append({
            'scheduled': scheduled_time,
            'actual': actual_time,
            'delay_minutes': round(delay, 1),
            'duration_minutes': duration_minutes,
            'success': success,
        })

    def check_compliance(self):
        if not self.executions:
            return {'compliant': False, 'reason': 'No executions recorded'}

        total = len(self.executions)
        on_time = sum(1 for e in self.executions if e['delay_minutes'] <= self.max_delay)
        within_duration = sum(1 for e in self.executions if e['duration_minutes'] <= self.max_duration)
        successful = sum(1 for e in self.executions if e['success'])

        compliant = sum(1 for e in self.executions
                       if e['delay_minutes'] <= self.max_delay
                       and e['duration_minutes'] <= self.max_duration
                       and e['success'])

        compliance_pct = (compliant / total) * 100
        return {
            'sla_name': self.name,
            'target_slo': self.slo,
            'compliance_pct': round(compliance_pct, 2),
            'sla_met': compliance_pct >= self.slo,
            'total_executions': total,
            'on_time': on_time,
            'within_duration': within_duration,
            'successful': successful,
            'compliant': compliant,
        }

sla = CronSLA("daily-backup", slo_pct=99.0, max_delay_minutes=30, max_duration_minutes=60)
base = datetime(2026, 6, 1, 2, 0)
for day in range(30):
    scheduled = base + timedelta(days=day)
    delay = 5 if day < 28 else 45
    duration = 30 if day < 28 else 90
    actual = scheduled + timedelta(minutes=delay)
    sla.record(scheduled, actual, duration, success=(day < 28))

report = sla.check_compliance()
print(f"SLA '{report['sla_name']}': {report['compliance_pct']}% compliant (target: {report['target_slo']}%)")
print(f"SLA Met: {report['sla_met']}, Breaches: {report['total_executions'] - report['compliant']}")

Expected output:

SLA 'daily-backup': 93.33% compliant (target: 99.0%)
SLA Met: False, Breaches: 2

SLA Report Generator

import time
from datetime import datetime, timedelta
import json

class SLAReport:
    def __init__(self, period_start, period_end):
        self.period_start = period_start
        self.period_end = period_end
        self.slas = []

    def add_sla(self, sla):
        self.slas.append(sla)

    def generate(self):
        report = {
            'period': {
                'start': self.period_start.isoformat(),
                'end': self.period_end.isoformat(),
            },
            'slas': []
        }
        for sla in self.slas:
            compliance = sla.check_compliance()
            report['slas'].append(compliance)
            status = 'PASS' if compliance['sla_met'] else 'BREACH'
            print(f"[{status:>6}] {sla.name}: {compliance['compliance_pct']:.1f}% (target {sla.slo}%)")

        total_compliant = sum(1 for s in report['slas'] if s['sla_met'])
        report['overall'] = f"{total_compliant}/{len(report['slas'])} SLAs met"
        print(f"\nOverall: {report['overall']}")
        return report

report = SLAReport(datetime(2026, 6, 1), datetime(2026, 6, 30))
sla1 = CronSLA("daily-backup", slo_pct=99.0, max_delay_minutes=30, max_duration_minutes=60)
sla2 = CronSLA("hourly-cache-warm", slo_pct=99.5, max_delay_minutes=5, max_duration_minutes=10)
sla3 = CronSLA("weekly-report", slo_pct=95.0, max_delay_minutes=120, max_duration_minutes=180)

for day in range(30):
    sla1.record(datetime(2026, 6, day+1, 2, 0), datetime(2026, 6, day+1, 2, 25), 25, True)
    sla2.record(datetime(2026, 6, day+1, 8, 0), datetime(2026, 6, day+1, 8, 3), 5, True)

sla3.record(datetime(2026, 6, 6, 9, 0), datetime(2026, 6, 6, 10, 30), 90, True)
sla3.record(datetime(2026, 6, 13, 9, 0), datetime(2026, 6, 13, 9, 45), 45, True)
sla3.record(datetime(2026, 6, 20, 9, 0), datetime(2026, 6, 20, 9, 30), 30, True)
sla3.record(datetime(2026, 6, 27, 9, 0), datetime(2026, 6, 27, 9, 35), 35, True)

report.add_sla(sla1)
report.add_sla(sla2)
report.add_sla(sla3)
report.generate()

Expected output:

[ PASS] daily-backup: 100.0% (target 99.0%)
[ PASS] hourly-cache-warm: 100.0% (target 99.5%)
[ PASS] weekly-report: 100.0% (target 95.0%)

Overall: 3/3 SLAs met

Common Mistakes

1. SLAs That Are Impossible to Measure

"Backup completes in a reasonable time" is not measurable. Define precise SLIs: "backup completes within 60 minutes of scheduled start time 99.9% of the time over a 30-day rolling window."

2. Same SLA for All Jobs

A database backup and a cache warming job have very different requirements. Define SLA tiers: Platinum (critical, 99.99%), Gold (important, 99.9%), Silver (standard, 99%). Each tier has different targets for delay, duration, and reliability.

Month-over-month SLA trends show whether reliability is improving. Track SLA compliance over time. Investigate if compliance is decreasing even if it is still above the target. Prevent gradual degradation.

4. SLA Without Breach Consequences

If an SLA breach has no consequences, it will be ignored. Define breach response: automatic post-mortem for Platinum breaches, review for Gold, log for Silver. Track breach frequency per service.

5. No Scheduled Uptime Calculation

"Scheduled uptime" differs from "24/7 uptime." A daily cron job that succeeds every day has 100% scheduled uptime even if it only runs for 60 minutes. Calculate uptime based on scheduled execution time, not wall clock time.

Practice Questions

1. What is a good SLA for a daily database backup?

Gold tier: 99.9% uptime (1 failure allowed per 3 years), completion within 4 hours of scheduled time, duration less than 2 hours. Alert on breach and trigger post-mortem.

2. How do you calculate scheduled uptime for a monthly cron job?

Scheduled uptime = (successful executions / scheduled executions) * 100. A monthly job that fails once in 12 months has 91.7% uptime. A daily job that fails once in 12 months has 99.7% uptime.

3. What is the difference between SLO and SLA?

SLO (Service Level Objective) is the internal target: 99.9% of jobs complete on time. SLA (Service Level Agreement) is the contractual commitment, which may be different from the SLO. SLO is typically stricter than SLA.

4. How do you define SLA tiers for cron jobs?

Platinum: critical infrastructure (backups, security scans) — 99.99%, 1-hour max delay. Gold: important business processes (reports, data sync) — 99.9%, 4-hour max delay. Silver: nice-to-have (cache warming, analytics) — 99%, 24-hour max delay.

Challenge

Build an SLA compliance system: (1) SLA definitions per job: target SLO (99.9%), max delay (30 min), max duration (60 min), tier (Platinum/Gold/Silver), (2) compliance calculator: rolling 30-day window, check delay/duration/success against targets, (3) SLA breach detector: alert on breach within 5 minutes, trigger post-mortem for Platinum breaches, (4) monthly report: per-job compliance, trend over 12 months, breach count and duration, (5) dashboard: SLA compliance gauge per job, trend chart, breach timeline.

FAQ

What is a good default SLA for cron jobs?

99.9% uptime (3 failures allowed per 3,000 executions), completion within 2x the expected duration, start within 30 minutes of scheduled time. Adjust based on criticality.

How often should SLA reports be generated?

Monthly reports for trend analysis. Real-time dashboards for current compliance. Weekly alerts for jobs approaching SLA breach. Quarterly reviews for SLA target adjustments.

What happens when an SLA is breached?

Automated post-mortem for critical jobs: analyze root cause, implement fix, verify fix. For non-critical: log and review in monthly meeting. Track breach frequency to identify systemic issues.

Should SLAs be the same for all environments?

No. Production SLAs should be strict. Staging SLAs can be relaxed (99% vs 99.9%). Development may have no formal SLA. This focuses reliability efforts where they matter most.

How do I handle SLA for jobs that are intentionally skipped (holidays, maintenance)?

Exclude intentionally skipped executions from SLA calculations. The job should report 'skipped' as a separate status. Track skipped-execution rate separately to ensure it does not mask failures.

Mini Project: SLA Compliance System

Build a cron SLA compliance system: (1) SLA definitions: per-job targets for timeliness (start within N minutes), duration (complete within N minutes), reliability (success rate over window), (2) compliance calculator: rolling 30-day window, Composite score requiring all SLIs to pass, (3) SLA breach alerts: immediate notification for Platinum breach, daily digest for Gold, weekly for Silver, (4) monthly report: per-job compliance %, trend over 12 months, breach analysis, (5) dashboard: compliance gauge per job, overall compliance %, breach timeline, (6) scheduled uptime: calculate uptime based on scheduled vs actual execution Windows.

What's Next

Now that you understand cron SLA compliance, explore capacity planning for cron, then learn about cron security hardening.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro