feat(backend): alert managers while a ticket keeps failing to print (setting print.alert_after_failures, default 2)
Owner request after step 1.11: hear about a failing ticket during service, not only when it's abandoned. - New notification print.failing (critical, all managers) when a print job's failed attempts reach print.alert_after_failures (ordering setting, default 2, 0 = never). Once per job; jobs on the same printer within an hour fold into one notification. print.failed_final (abandoned) stays. - Both the first attempt (route-and-print, sent after its commit) and the retry sweep report it. - Texts in en/el; tests for 1/2/3/0 and folding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,3 +157,27 @@ def test_print_failed_final(client, db, people):
|
||||
assert item["key"] == "print.failed_final" and item["count"] == 2
|
||||
assert item["message"] == "A ticket for order #42 never printed on 999 (7 attempts)."
|
||||
assert keys(client, people["waiter"][1]) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("setting,alerted_at", [(None, 2), ("1", 1), ("3", 3), ("0", None)])
|
||||
def test_print_failing_after_n_attempts(client, db, people, setting, alerted_at):
|
||||
from models.settings import PosSettings
|
||||
from services.printer_service import _notify_print_failing
|
||||
if setting is not None:
|
||||
db.merge(PosSettings(key="print.alert_after_failures", value=setting))
|
||||
db.commit()
|
||||
pj = SimpleNamespace(id=5, order_id=42, printer_id=3, retry_count=0)
|
||||
seen = []
|
||||
for attempt in range(1, 5):
|
||||
pj.retry_count = attempt
|
||||
_notify_print_failing(db, pj, "Bar")
|
||||
if keys(client, people["store_manager"][1]) and not seen:
|
||||
seen.append(attempt)
|
||||
assert (seen[0] if seen else None) == alerted_at
|
||||
if alerted_at:
|
||||
item = listing(client, people["store_manager"][1])["items"][0]
|
||||
assert item["key"] == "print.failing" and item["count"] == 1 # once per job
|
||||
assert "still retrying" in item["message"]
|
||||
# another job on the same printer within the hour folds in
|
||||
_notify_print_failing(db, SimpleNamespace(id=6, order_id=43, printer_id=3, retry_count=alerted_at), "Bar")
|
||||
assert listing(client, people["store_manager"][1])["items"][0]["count"] == 2
|
||||
|
||||
Reference in New Issue
Block a user