feat(backend): platform notifications service with audiences, dedupe, read state and first producers
Platform v2 step 1.11 (APPS_PLATFORM section 10).
- notifications + notification_reads (revision 0010). Text = i18n key notification.<key> + params,
rendered in the reader's language (en, el added).
- core/notifications.py: notify(key, severity, audience, params, dedupe_key, ttl/expires_at, fold)
never raises; audience all_managers | perm:<key> | user:<id>; a live duplicate only bumps
count/last_at (no unread reset, no event). New ones emit WS platform_notification {id} to the
audience's users (current apps ignore it; phase 2 manager shows it).
- API (core, /api/platform/notifications; /api/notifications is chat's): list with unread count,
POST /{id}/read, POST /read-all.
- Producers: license.limit_reached (device pairing/reassign/over-limit device, per module/limit/day,
owners), license.expiring (14/7/3/1 days, from apply_license, owners), support.access_used (each
use, core.settings.manage), print.failed_final (abandoned retry job, per printer/hour, managers).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2184,6 +2184,7 @@ def _retry_sweep():
|
||||
# The ticket never printed and never will: this is the job's final failure.
|
||||
logger.warning("print.job.abandoned job=%s order=%s attempts=%s reason=order_closed",
|
||||
pj.id, pj.order_id, pj.retry_count)
|
||||
_notify_print_failed(db, pj)
|
||||
continue
|
||||
|
||||
item_ids = json.loads(pj.item_ids or "[]")
|
||||
@@ -2249,6 +2250,17 @@ def _retry_sweep():
|
||||
db.close()
|
||||
|
||||
|
||||
def _notify_print_failed(db, pj) -> None:
|
||||
"""print.failed_final: managers learn that a ticket never printed (one notification per
|
||||
printer per hour; further failures in that hour are counted on it)."""
|
||||
from core.notifications import notify
|
||||
printer = db.get(Printer, pj.printer_id)
|
||||
notify("print.failed_final", "critical", "all_managers",
|
||||
{"order_id": pj.order_id, "printer": printer.name if printer else str(pj.printer_id),
|
||||
"attempts": pj.retry_count or 0, "job_id": pj.id},
|
||||
dedupe_key=f"print.failed_final:{pj.printer_id}", ttl=datetime.timedelta(hours=1), db=db)
|
||||
|
||||
|
||||
def _retry_loop():
|
||||
while True:
|
||||
_time.sleep(_RETRY_INTERVAL)
|
||||
|
||||
Reference in New Issue
Block a user