04 / REUSABLE DAILY OPERATIONS · LESSON 13

Compose a reusable system assessment

Import small policy functions and keep evidence collection separate from classification.

15 min · learn at your pace

Give each function a narrow responsibility

An administration tool becomes easier to change when reading files, applying policy and writing reports are separate operations. This lesson supplies ops_rules.py beside main.py. It contains the capacity rule you already used and a backup-age rule. Import those functions instead of duplicating their boundary logic.

backup_status returns ok, stale or unknown. A backup exactly the maximum age is acceptable; a strictly older backup is stale. Missing, invalid, timezone-naive and future timestamps are unknown. A future timestamp is not proof of a very recent successful backup.

Compose observations into an honest status

The top-level function assesses one supplied snapshot. If its disk data is missing, pass unavailable values to the capacity rule. Build issue codes from each rule's result and sort them. A snapshot is healthy only when both rules return ok; otherwise it needs attention.

The caller supplies now, making tests and repeated assessments deterministic. Reading the wall clock inside several helper functions could produce slightly different decisions at a boundary.

Keep a main guard around demonstrations so importing the script does not start work. This single-file editor imports a bundled helper from the virtual workspace. It does not install a package or read the browser device's disk and backup state.

Try an example.py
from ops_rules import backup_status
print(backup_status("2026-11-16T12:00:00Z", "2026-11-17T12:00:00Z", 24))
YOUR TURN

Put it into practice.

Define evaluate_snapshot(snapshot, policy, now) using the supplied ops_rules.capacity_status(total,free,minimum) and backup_status(last_success,now,maximum_hours). Policy is already validated. Missing/non-object disk supplies unavailable total/free; backup_at may be missing. Return status (healthy only when both rules say ok, otherwise attention), free_percent, backup_status, and alphabetically sorted issue codes disk_low, disk_unknown, backup_stale or backup_unknown as applicable. Do not mutate inputs. now is an aware timestamp, supplied by the caller.

See an explained solution
One way to solve it.py
from ops_rules import capacity_status, backup_status

def evaluate_snapshot(snapshot, policy, now):
    disk = snapshot.get("disk")
    if not isinstance(disk, dict):
        disk = {}
    capacity = capacity_status(disk.get("total"), disk.get("free"), policy["min_free_percent"])
    backup = backup_status(snapshot.get("backup_at"), now, policy["backup_max_age_hours"])
    issues = []
    if capacity["status"] != "ok":
        issues.append("disk_" + capacity["status"])
    if backup != "ok":
        issues.append("backup_" + backup)
    return {"status": "attention" if issues else "healthy", "free_percent": capacity["free_percent"],
            "backup_status": backup, "issues": sorted(issues)}

if __name__ == "__main__":
    print(evaluate_snapshot({"disk":{"total":100,"free":15},"backup_at":None}, {"min_free_percent":20,"backup_max_age_hours":24}, "2026-11-17T12:00:00Z"))

The composed function contains no file I/O or clock reads. Reusable rules retain the exact boundaries, while the assessment exposes both a summary and the reasons behind it.