Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
review_attention.py · 2.4 KB · 75 lines
1"""system_review_attention -- runs where a person has to decide the money.
2
3COUNT {} -> {count, detail}
4
5Every row here is a run submitted to a provider whose outcome was never
6learned, parked at `needs_review` with its hold still on. The sweeper put
7it there deliberately: releasing would give away what the provider may
8already have charged, and charging would bill a customer for work that
9may never have arrived, so the machine stopped rather than guess.
10
11Which makes this the one queue on the box where **doing nothing costs
12somebody money continuously.** A backorder makes a customer wait; an
13unresolved run holds their balance down against a job nobody will ever
14settle. That is why the detail leads with the amount held rather than the
15age: "3 waiting" is a number, "3 waiting, $18.00 held" is the reason to
16open the page, and it is the same number the customer is looking at in
17their own balance.
18
19Severity `warning`, matching the rest of the "nobody chose to be in this
20queue" family, and deliberately not `urgent` -- urgent is reserved for
21the server reporting that it stopped doing its own work. Here the server
22did exactly what it should.
23
24Degrades to zero when template_runs is absent, the same posture every
25other provider takes: a rollup pass should not log an error every five
26minutes about a collection nobody installed.
27"""
28
29import os
30
31import object_records
32import object_template_runs
33
34ACTOR = "system_review_attention"
35RUNS = "template_runs"
36
37
38def _text(value):
39 return str(value if value is not None else "").strip()
40
41
42def _int(value, default=0):
43 try:
44 return int(str(value).strip())
45 except (TypeError, ValueError):
46 return default
47
48
49def _base_dir():
50 return os.environ.get("DBBASIC_DATA_DIR", "data")
51
52
53def _money(cents):
54 sign = "-" if cents < 0 else ""
55 amount = abs(int(cents))
56 return f"{sign}${amount // 100}.{amount % 100:02d}"
57
58
59def COUNT(request):
60 try:
61 runs = object_records.read_collection_records(RUNS, base_dir=_base_dir())
62 except Exception:
63 return {"count": 0}
64
65 waiting = [run for run in runs
66 if _text(run.get("status"))
67 == object_template_runs.NEEDS_REVIEW_STATUS]
68 if not waiting:
69 return {"count": 0}
70
71 held = sum(_int(run.get("price_cents")) for run in waiting)
72 detail = f"{len(waiting)} waiting"
73 if held:
74 detail += f", {_money(held)} held"
75 return {"count": len(waiting), "detail": detail}