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.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
mail_sync_attention.py · 1.7 KB · 47 lines
| 1 | """system_mail_sync_attention -- how many mail accounts keep failing to sync. |
| 2 | |
| 3 | COUNT only (docs/package-authoring.md, the attention contract). An account |
| 4 | counts when it is enabled and its last object_mail.ATTENTION_AFTER passes in |
| 5 | a row all failed: one failure is a network blip, three is a changed |
| 6 | password or a server that has gone away, and nobody will find out from the |
| 7 | inbox itself, because a mailbox that stopped syncing looks exactly like a |
| 8 | quiet one. That look-alike is the failure the predecessor's silent |
| 9 | ``except: pass`` produced, and this count is what ends it. |
| 10 | |
| 11 | The count is deployment-wide, as every attention count is, so the detail |
| 12 | names no person and no address. The owner reads which account and why on |
| 13 | /mail/accounts, where sync_error is shown in full. |
| 14 | |
| 15 | A box without app-mail-sync installed reads zero rather than raising. |
| 16 | """ |
| 17 | |
| 18 | import os |
| 19 | |
| 20 | import object_mail |
| 21 | import object_records |
| 22 | |
| 23 | |
| 24 | def _text(value): |
| 25 | return str(value if value is not None else "").strip() |
| 26 | |
| 27 | |
| 28 | def _int(value): |
| 29 | try: |
| 30 | return int(_text(value) or 0) |
| 31 | except ValueError: |
| 32 | return 0 |
| 33 | |
| 34 | |
| 35 | def COUNT(request): |
| 36 | base = os.environ.get("DBBASIC_DATA_DIR", "data") |
| 37 | try: |
| 38 | accounts = object_records.read_collection_records("mail_accounts", base_dir=base) |
| 39 | except (LookupError, OSError, ValueError): |
| 40 | return {"count": 0} |
| 41 | failing = [row for row in accounts |
| 42 | if _text(row.get("enabled")).lower() not in {"false", "0", "no", "off"} |
| 43 | and _int(row.get("sync_attempts")) >= object_mail.ATTENTION_AFTER] |
| 44 | if not failing: |
| 45 | return {"count": 0} |
| 46 | return {"count": len(failing), |
| 47 | "detail": f"failed {object_mail.ATTENTION_AFTER} or more syncs in a row"} |