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
queue.py · 1.8 KB · 41 lines
| 1 | """queue -- the daemon's deferred-work queue. |
| 2 | |
| 3 | object_daemon.process_queue reads `msg_*` keys out of THIS object's state |
| 4 | on every poll and executes the target object each message names. The queue |
| 5 | primitive already supports everything deferred work normally needs: |
| 6 | |
| 7 | visible_after run no earlier than this epoch second (a DELAY) |
| 8 | priority_level higher goes first |
| 9 | expires_at drop it if it never became runnable in time |
| 10 | max_attempts retry with exponential backoff (2**attempts seconds), |
| 11 | then park the message as failed rather than looping |
| 12 | queue_name independent named queues |
| 13 | |
| 14 | Enqueue with object_daemon_control.enqueue_message() or POST |
| 15 | /daemon/queue/messages. Status walks pending -> processing -> |
| 16 | completed | failed | expired, and the message keeps its attempt count, so |
| 17 | a dead job is inspectable instead of vanishing. |
| 18 | |
| 19 | Like the scheduler object this is inert on purpose -- the work is data in |
| 20 | its state, and the contract lives in object_daemon.process_queue. Without |
| 21 | this file the daemon simply reports "Queue: no queue object" and every |
| 22 | enqueued message waits forever, which is why it ships in a package. |
| 23 | |
| 24 | What this queue is NOT: a worker pool. Messages execute inside the daemon's |
| 25 | poll loop, so a job that takes thirty seconds delays that daemon's other |
| 26 | passes by thirty seconds. That is fine for follow-on writes, notifications, |
| 27 | recomputes and short fetches; heavy or long work (image processing, OCR, |
| 28 | model calls) wants its own process and should say so plainly rather than |
| 29 | quietly starving the aging pass. |
| 30 | """ |
| 31 | |
| 32 | |
| 33 | def GET(request): |
| 34 | return {"ok": True, |
| 35 | "note": "msg_* entries in this object's state drive " |
| 36 | "object_daemon.process_queue; enqueue via " |
| 37 | "/daemon/queue/messages"} |
| 38 | |
| 39 | |
| 40 | def POST(request): |
| 41 | return {"ok": True} |