Batteries
queue — background queue
Offload heavy work to a FIFO background worker so a webhook can respond quickly.
So a webhook can respond quickly, you offload heavy work to the background:
use queue
queue.on "send" \job -> tools.send job.ph job.body # the handler
queue.push "send" {ph:phone body:text} # add to the queuequeue.on <name> <handler>— the handler for jobs with this name. The handler takes a singlejobargument — this is the payload given toqueue.push(a map).queue.push <name> <payload>— adds a job to the queue. The payload is optional (if not given,nil). It does not block — it returns immediately, and the job runs in the background.- Jobs run on a single worker thread, FIFO (in arrival order) — ordering is guaranteed. An error inside a handler does not kill the worker.
- If
pushis written beforeon, the job waits in the queue and runs once the handler is registered (order-independent). - The worker is a background thread — it processes the queue while a server
(
http.serve/ws.serve) orcron.runholds the process. In a queue-only script you need one of these blocking calls to hold the process.