askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
backup_attention.py · 1.8 KB · 46 lines
| 1 | """system_backup_attention -- scheduled backups that failed or went stale. |
| 2 | |
| 3 | COUNT {} -> {count, detail} |
| 4 | |
| 5 | `urgent`, beside scheduler_failures and for the same reason: this is the |
| 6 | machine reporting that it stopped doing its own work, and of all its work |
| 7 | this is the one whose silent failure cannot be apologised for. A backup |
| 8 | that stopped running looks exactly like a backup that is running until the |
| 9 | day somebody needs it. |
| 10 | |
| 11 | The count is the number of PROBLEMS object_backup_schedule.status names |
| 12 | (the last backup failed, no good backup within two intervals, the last |
| 13 | restore test failed, no passing restore test within two intervals, the |
| 14 | destination is refused, the after-command failed), and the detail is the |
| 15 | first one in words. Zero when everything is fine -- and zero when backups |
| 16 | are off, because turning them on is the operator's decision and an alarm |
| 17 | on every fresh install would teach everyone to ignore the band; the |
| 18 | dashboard and /admin/status say "off" in words instead. |
| 19 | |
| 20 | No `reads` in the manifest, deliberately: the attention layer shows a |
| 21 | provider that names no collections to admins only, and what a backup |
| 22 | destination is and whether it works is an admin's business. |
| 23 | |
| 24 | COUNT rather than GET or POST: the verb is the contract with the daemon's |
| 25 | attention pass. A status that cannot be read raises, so the rollup keeps |
| 26 | the last count and records the error rather than reporting a calm box. |
| 27 | """ |
| 28 | |
| 29 | import os |
| 30 | |
| 31 | import object_backup_schedule |
| 32 | |
| 33 | |
| 34 | def _base_dir(): |
| 35 | return os.environ.get("DBBASIC_DATA_DIR", "data") |
| 36 | |
| 37 | |
| 38 | def COUNT(request): |
| 39 | payload = object_backup_schedule.status(_base_dir()) |
| 40 | problems = payload.get("problems") or [] |
| 41 | if not problems: |
| 42 | return {"count": 0} |
| 43 | detail = str(problems[0].get("message") or "") |
| 44 | if len(problems) > 1: |
| 45 | detail += f" (+{len(problems) - 1} more)" |
| 46 | return {"count": len(problems), "detail": detail} |