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