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
dispute_attention.py · 2.7 KB · 77 lines
1"""system_dispute_attention -- claims nobody has picked up.
2
3COUNT {} -> {count, detail}
4
5A dispute at `open` is a customer who has said something went wrong and
6has heard nothing back. It is the only queue on this box where the thing
7waiting is a person rather than a document: a short-received purchase
8order waits patiently, a parcel on the returns bench waits patiently, and
9a customer telling you their order never arrived is drafting a chargeback
10while they wait. That is why the detail names the oldest one in days --
11three claims a day old and three claims a fortnight old are the same row
12count and completely different mornings.
13
14`investigating` is deliberately NOT counted. Somebody has it; the number
15exists to find the claims nobody has, and a count that also includes work
16in progress can never reach zero, which is how a badge stops meaning
17anything. The bench at /disputes shows the whole ladder, because the
18person standing at it needs to see what is in flight as well as what is
19untouched, and `status` is one click away in the filter bar.
20
21COUNT rather than GET or POST: the verb is the contract with the daemon's
22attention pass. A missing collection reads as zero -- a server with no
23disputes app has no disputes -- while a genuine failure raises, so the
24rollup records it and keeps the last count rather than reporting a clear
25queue nobody cleared.
26"""
27
28import os
29from datetime import datetime, timezone
30
31import object_records
32
33ACTOR = "system_dispute_attention"
34
35# Raised and untouched. `investigating` has a human on it, `resolved` and
36# `withdrawn` are endings.
37WAITING_STATUS = "open"
38
39
40def _base_dir():
41 return os.environ.get("DBBASIC_DATA_DIR", "data")
42
43
44def _text(value):
45 return str(value if value is not None else "").strip()
46
47
48def _age_days(value):
49 text = _text(value).replace("Z", "+00:00")
50 if not text:
51 return None
52 try:
53 stamp = datetime.fromisoformat(text)
54 except ValueError:
55 return None
56 if stamp.tzinfo is None:
57 stamp = stamp.replace(tzinfo=timezone.utc)
58 return (datetime.now(timezone.utc) - stamp).days
59
60
61def COUNT(request):
62 try:
63 rows = object_records.read_collection_records("disputes",
64 base_dir=_base_dir())
65 except Exception:
66 return {"count": 0}
67
68 waiting = [row for row in rows
69 if _text(row.get("status")) == WAITING_STATUS]
70 if not waiting:
71 return {"count": 0}
72
73 ages = [days for days in (_age_days(row.get("created_at"))
74 for row in waiting) if days is not None]
75 oldest = max(ages) if ages else 0
76 detail = f"oldest waiting {oldest} days" if oldest else ""
77 return {"count": len(waiting), "detail": detail}