Reference
Railway worker
How the continuous Railway worker claims, runs and retries jobs from the Appwrite jobs table.
The production worker service uses /railway.worker.json: build runs
pnpm worker:check (loads the handler registry without connecting), and the
service runs pnpm worker continuously with restartPolicyType: ON_FAILURE.
There is no cron schedule and no scheduler service.
What the worker does
scripts/worker.mts wires lib/jobs/worker.ts to getRepositories():
- Sweeps (every minute, in-process): pending in-app notifications whose
deliver_athas passed becomenotifyjobs, and scheduled posts that are due and were not yet handed to SocialBu becomepublish-postjobs. Sweep jobs use deterministic ids, so several replicas never double-enqueue. Hourly, lease rows older than seven days are purged. - Claims up to
WORKER_CONCURRENCY(default 2) queued jobs whoserun_athas passed, plus running jobs whose lease expired. A claim creates the rowjob_leases/<jobId>.<attempt>; a 409 means another worker won. - Runs the handler from
lib/jobs/handlers.ts, renewing the lease every third of its length (default lease 2 minutes). Success marks the jobsucceeded; failures retry with exponential backoff untilmax_attempts, then becomedead.PermanentJobErrorstops retries;RetryJobErrorpicks the next attempt time. - Sleeps adaptively (1 s up to 20 s) when idle.
POST /wakeonWORKER_PORT(orPORT) cuts the sleep short; web code can callwakeWorker()(lib/jobs/wake.ts) after enqueueing, usingWORKER_WAKE_URLon Railway private networking.GET /healthreports liveness.
Handlers
| Job type | Owner | Status |
|---|---|---|
notify | backend | Implemented: flips a pending notification to delivered. |
render-slideshow | render engine | Placeholder: retries every 15 minutes until a handler is registered. |
publish-post | publishing | Placeholder: retries every 15 minutes until a handler is registered. |
Operating it
pnpm worker:onceruns one forced sweep and one claim batch, then exits.- Required variables:
APPWRITE_ENDPOINT,APPWRITE_PROJECT_ID,APPWRITE_API_KEY.LUMENCLIP_DATA_BACKENDmust be unset orappwrite. - Verify a deploy by checking the
worker startedlog line and, after enqueuing work,job succeededlines. Never print variable values.