@clipboard-health/mongo-jobs 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -204,7 +204,7 @@ const backgroundJobs = new BackgroundJobs();
|
|
|
204
204
|
// For jobs with constructor dependencies, register an instance
|
|
205
205
|
const emailService = {
|
|
206
206
|
async send(to: string, subject: string, body: string) {
|
|
207
|
-
console.log(`Sending email to ${to}: ${subject}`);
|
|
207
|
+
console.log(`Sending email to ${to}: ${subject} : ${body}`);
|
|
208
208
|
},
|
|
209
209
|
};
|
|
210
210
|
|
|
@@ -283,9 +283,13 @@ await backgroundJobs.enqueue(MyJob, {
|
|
|
283
283
|
<embedex source="packages/mongo-jobs/examples/usage/enqueueWithOptions.ts">
|
|
284
284
|
|
|
285
285
|
```ts
|
|
286
|
+
import type { ClientSession } from "mongodb";
|
|
287
|
+
|
|
286
288
|
import { backgroundJobs } from "./jobsRegistry";
|
|
287
289
|
import { MyJob } from "./myJob";
|
|
288
290
|
|
|
291
|
+
declare const mongoSession: ClientSession;
|
|
292
|
+
|
|
289
293
|
// Enqueue with options
|
|
290
294
|
await backgroundJobs.enqueue(
|
|
291
295
|
MyJob,
|
|
@@ -356,13 +360,13 @@ await backgroundJobs.start(["notifications"], {
|
|
|
356
360
|
useChangeStream: true,
|
|
357
361
|
|
|
358
362
|
// Lock timeout for stuck jobs, in ms (default: 600000 = 10 minutes)
|
|
359
|
-
lockTimeoutMS:
|
|
363
|
+
lockTimeoutMS: 300_000,
|
|
360
364
|
|
|
361
365
|
// Interval to check for stuck jobs, in ms (default: 60000 = 1 minute)
|
|
362
|
-
unlockJobsIntervalMS:
|
|
366
|
+
unlockJobsIntervalMS: 30_000,
|
|
363
367
|
|
|
364
368
|
// Interval to refresh queue list, in ms (default: 30000 = 30 seconds)
|
|
365
|
-
refreshQueuesIntervalMS:
|
|
369
|
+
refreshQueuesIntervalMS: 60_000,
|
|
366
370
|
|
|
367
371
|
// Exclude specific queues from processing
|
|
368
372
|
exclude: ["low-priority-queue"],
|
|
@@ -377,7 +381,7 @@ await backgroundJobs.start(["notifications"], {
|
|
|
377
381
|
import { backgroundJobs } from "./jobsRegistry";
|
|
378
382
|
|
|
379
383
|
// Graceful shutdown
|
|
380
|
-
await backgroundJobs.stop(
|
|
384
|
+
await backgroundJobs.stop(30_000); // Wait up to 30 seconds for jobs to complete
|
|
381
385
|
```
|
|
382
386
|
|
|
383
387
|
</embedex>
|
|
@@ -466,8 +470,8 @@ Prevent duplicate jobs from being enqueued or running simultaneously:
|
|
|
466
470
|
<embedex source="packages/mongo-jobs/examples/usage/uniqueSimple.ts">
|
|
467
471
|
|
|
468
472
|
```ts
|
|
469
|
-
import { backgroundJobs } from "./jobsRegistry";
|
|
470
473
|
import { ProcessUserJob } from "./jobs/processUserJob";
|
|
474
|
+
import { backgroundJobs } from "./jobsRegistry";
|
|
471
475
|
|
|
472
476
|
// Simple uniqueness - single unique key for both enqueued and running
|
|
473
477
|
await backgroundJobs.enqueue(
|
|
@@ -495,8 +499,8 @@ if there is one running, cause we don't know if the current recalculation will i
|
|
|
495
499
|
<embedex source="packages/mongo-jobs/examples/usage/uniqueAdvanced.ts">
|
|
496
500
|
|
|
497
501
|
```ts
|
|
498
|
-
import { backgroundJobs } from "./jobsRegistry";
|
|
499
502
|
import { ProcessUserJob } from "./jobs/processUserJob";
|
|
503
|
+
import { backgroundJobs } from "./jobsRegistry";
|
|
500
504
|
|
|
501
505
|
// Advanced uniqueness - separate keys for enqueued vs running states
|
|
502
506
|
await backgroundJobs.enqueue(
|
|
@@ -519,8 +523,8 @@ await backgroundJobs.enqueue(
|
|
|
519
523
|
<embedex source="packages/mongo-jobs/examples/usage/uniqueMultipleEnqueued.ts">
|
|
520
524
|
|
|
521
525
|
```ts
|
|
522
|
-
import { backgroundJobs } from "./jobsRegistry";
|
|
523
526
|
import { SendEmailJob } from "./jobs/sendEmailJob";
|
|
527
|
+
import { backgroundJobs } from "./jobsRegistry";
|
|
524
528
|
|
|
525
529
|
// Example: Allow multiple enqueued but only one running
|
|
526
530
|
await backgroundJobs.enqueue(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/mongo-jobs",
|
|
3
3
|
"description": "MongoDB-powered background jobs.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"cron-parser": "5.4.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"tslib": "2.8.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@clipboard-health/util-ts": "3.18.
|
|
12
|
+
"@clipboard-health/util-ts": "3.18.2",
|
|
13
13
|
"@opentelemetry/api": "1.9.0",
|
|
14
14
|
"mongodb": "6.18.0",
|
|
15
15
|
"mongoose": "8.18.0"
|