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
ref https://linear.app/ghost/issue/ENG-2028/
We created this persisted queue using a MySQL-based queue to prototype a
more robust queuing system, intending to use Redis, RabbitMQ, or the
like. We didn't find enough benefit from this and found other
constraints, primarily r/w to the db being burdensome, and not enough
benefit to justify the move to RMQ/Redis at this time.
Given that, we're removing the job queue manager. We've previously
removed any calling code, so now we're pulling the class itself and will
follow up with a migration (or two) to clean up the jobs table schema
and entries.
@@ -54,39 +44,16 @@ Ghost supports three types of jobs:
54
44
- Good for CPU-intensive tasks
55
45
- Can be scheduled or recurring
56
46
57
-
3.**Persisted Queue Jobs**
58
-
- Stored in database
59
-
- Survive server restarts
60
-
- Best for background tasks
61
-
- Can be monitored and retried
62
-
63
47
## Background Job Requirements
64
48
65
-
Both offloaded and queued jobs must:
49
+
Offloaded jobs must:
66
50
67
51
- Have a unique name
68
52
- Be idempotent (safe to run multiple times)
69
53
- Use minimal parameters (prefer using IDs rather than full objects)
70
54
- Import their own dependencies
71
55
- Primarily use DB or API calls
72
56
73
-
## Configuration
74
-
75
-
The job queue can be configured through Ghost's config:
76
-
77
-
```js
78
-
jobs: {
79
-
queue: {
80
-
enabled:true,
81
-
maxWorkers:1,
82
-
pollMinInterval:1000, // 1 sec
83
-
pollMaxInterval:60000, // 1 min
84
-
queueCapacity:500, // Max queued jobs
85
-
fetchCount:500// Max jobs per poll
86
-
}
87
-
}
88
-
```
89
-
90
57
## Advanced Usage
91
58
92
59
Below is a sample code to wire up job manger and initialize jobs. This is the simplest way to interact with the job manager - these jobs do not persist after reboot:
@@ -182,66 +149,3 @@ Offloaded jobs are running on dedicated worker threads which makes their lifecyc
182
149
4. When **exceptions** happen and expected outcome is to terminate current job, leave the exception unhandled allowing it to bubble up to the job manager. Unhandled exceptions [terminate current thread](https://nodejs.org/dist/latest-v14.x/docs/api/worker_threads.html#worker_threads_event_error) and allow for next scheduled job execution to happen.
183
150
184
151
For more nuances on job structure best practices check [bree documentation](https://github.com/breejs/bree#writing-jobs-with-promises-and-async-await).
185
-
186
-
### Implementation Notes
187
-
For any persisted tasks, the Job Manager has a queue based on the `jobs` table. This table is polled regularly and processed with a single worker, and is ideal for background tasks, e.g. updating member analytics. (see notes below about job types)
188
-
189
-
```js
190
-
// the job manager is typically injected into the consumer service via the service wrapper
191
-
// from there
192
-
constJobManager=require('../../services/jobs');
193
-
...
194
-
195
-
// ** job submission should be handled by the wrapper service **
196
-
// this could be via subscription to events, emitted by the wrapped service(s)
In most cases, jobs should not be submitted by services directly. Because they must import what is needed, it would require too many injected dependencies.
226
-
227
-
### Adjusting the Job Queue
228
-
The queue manager will poll the `jobs` table every minute unless jobs are being actively or were recently processed, where it will instead poll every second.
229
-
230
-
The job queue has a few other config flags for the number of workers, polling rate, max jobs to process, etc.
231
-
232
-
```
233
-
services: {
234
-
jobs: {
235
-
queue: {
236
-
enabled: true,
237
-
reportStats: true,
238
-
maxWorkers: 1,
239
-
logLevel: 'info' | 'error',
240
-
pollMinInterval: 1000, // 1 sec
241
-
pollMaxInterval: 60000, // 1 min
242
-
queueCapacity: 500, // # of jobs in the process queue at any time
243
-
fetchCount: 500 // max # of jobs fetched in each poll
0 commit comments