You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 690ca72
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .cursor/rules/background-work.mdc
+3-11Lines changed: 3 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
description: Background work on the backend, cron jobs in the scheduler vs tasks in the Postgres queue, transactional enqueue, retries, idempotent handlers, PROCESS_ROLE for running a separate worker
2
+
description: Background work on the backend, cron jobs in the scheduler vs tasks in the Postgres queue, transactional enqueue, retries, idempotent handlers
3
3
globs: apps/backend/src/**/*
4
4
alwaysApply: false
5
5
---
@@ -64,14 +64,6 @@ The task commits or rolls back with the row. A row can never sit in `queued` wit
64
64
65
65
Workers are off under `NODE_ENV=test`, so nothing runs behind a test's back. `setupIntegrationTest()` starts the queue, which means code under test can enqueue. To test a handler, call the queue's `run` directly with a task object. To test the queue itself, see `src/libs/queue/queue.spec.ts`.
66
66
67
-
## Running a separate worker
67
+
## Where tasks run
68
68
69
-
`PROCESS_ROLE` picks what a process does. Same image, same start command.
70
-
71
-
| Role | API routes | Cron jobs | Task workers |
72
-
| --- | --- | --- | --- |
73
-
| `all` (default) | yes | yes | yes |
74
-
| `web` | yes | no | no |
75
-
| `worker` | `/health` only | yes | yes |
76
-
77
-
Start with `all`. When background work starts slowing requests down, deploy the backend a second time with `PROCESS_ROLE=worker` (same database, bucket, and provider keys, no public domain, no migration command) and set the public one to `web`. The two never talk to each other. Postgres is the hand-off, so you can run as many workers as you need.
69
+
Inside the backend process, next to the API and the scheduler. `main.ts` starts it with `startQueues({ queues, postgres })`, and it runs on that connection, so it opens no pool of its own. The queue is free until used: with nothing in `src/queues/index.ts` it opens no connections and creates no schema. There is no separate worker to deploy. Every instance works tasks, each up to the queue's `concurrency`, so adding a backend replica adds capacity. Keep `concurrency` low for anything memory-heavy: it shares the process with your requests.
0 commit comments