@tsed/bullmq 7.39.0 → 7.40.0
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/jest.config.js +1 -1
- package/lib/cjs/dispatchers/JobDispatcher.js +5 -2
- package/lib/cjs/dispatchers/JobDispatcher.js.map +1 -1
- package/lib/esm/dispatchers/JobDispatcher.js +5 -2
- package/lib/esm/dispatchers/JobDispatcher.js.map +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/dispatchers/JobDispatcher.d.ts +2 -2
- package/package.json +7 -7
- package/src/dispatchers/JobDispatcher.spec.ts +47 -1
- package/src/dispatchers/JobDispatcher.ts +6 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { InjectorService } from "@tsed/di";
|
|
2
2
|
import { JobMethods } from "../contracts";
|
|
3
3
|
import { Type } from "@tsed/core";
|
|
4
|
-
import { Job as BullMQJob } from "bullmq";
|
|
4
|
+
import { Job as BullMQJob, JobsOptions } from "bullmq";
|
|
5
5
|
export declare class JobDispatcher {
|
|
6
6
|
private readonly injector;
|
|
7
7
|
constructor(injector: InjectorService);
|
|
8
|
-
dispatch<T extends JobMethods>(job: Type<T>, payload?: Parameters<T["handle"]>[0]): Promise<BullMQJob>;
|
|
8
|
+
dispatch<T extends JobMethods>(job: Type<T>, payload?: Parameters<T["handle"]>[0], options?: JobsOptions): Promise<BullMQJob>;
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/bullmq",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.40.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "BullMQ integration for Ts.ED",
|
|
6
6
|
"keywords": [
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"tslib": "2.5.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/common": "7.
|
|
33
|
-
"@tsed/core": "7.
|
|
34
|
-
"@tsed/di": "7.
|
|
35
|
-
"@tsed/eslint": "7.39.
|
|
36
|
-
"@tsed/schema": "7.
|
|
37
|
-
"@tsed/typescript": "7.39.
|
|
32
|
+
"@tsed/common": "7.40.0",
|
|
33
|
+
"@tsed/core": "7.40.0",
|
|
34
|
+
"@tsed/di": "7.40.0",
|
|
35
|
+
"@tsed/eslint": "7.39.1",
|
|
36
|
+
"@tsed/schema": "7.40.0",
|
|
37
|
+
"@tsed/typescript": "7.39.1",
|
|
38
38
|
"bullmq": "^4.12.3",
|
|
39
39
|
"eslint": "^8.12.0",
|
|
40
40
|
"ts-mockito": "^2.6.1"
|
|
@@ -9,7 +9,7 @@ import {instance, mock, verify, when, objectContaining} from "ts-mockito";
|
|
|
9
9
|
backoff: 69
|
|
10
10
|
})
|
|
11
11
|
class ExampleTestJob implements JobMethods {
|
|
12
|
-
handle(payload: {msg: string}) {}
|
|
12
|
+
handle(payload: { msg: string }) {}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
@JobController("queue-not-configured", "not-configured")
|
|
@@ -49,4 +49,50 @@ describe("JobDispatcher", () => {
|
|
|
49
49
|
)
|
|
50
50
|
).once();
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
it('should overwrite job options defined by the job', async () => {
|
|
54
|
+
const injector = mock(InjectorService);
|
|
55
|
+
const queue = mock(Queue);
|
|
56
|
+
when(queue.name).thenReturn("default");
|
|
57
|
+
|
|
58
|
+
when(injector.getMany("bullmq:queue")).thenReturn([instance(queue)]);
|
|
59
|
+
|
|
60
|
+
const dispatcher = new JobDispatcher(instance(injector));
|
|
61
|
+
|
|
62
|
+
await dispatcher.dispatch(ExampleTestJob, {msg: "hello test"}, {backoff: 42, jobId: 'ffeeaa'});
|
|
63
|
+
|
|
64
|
+
verify(
|
|
65
|
+
queue.add(
|
|
66
|
+
"example-job",
|
|
67
|
+
objectContaining({msg: "hello test"}),
|
|
68
|
+
objectContaining({
|
|
69
|
+
backoff: 42,
|
|
70
|
+
jobId: 'ffeeaa'
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
).once();
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('should keep existing options and add new ones', async () => {
|
|
77
|
+
const injector = mock(InjectorService);
|
|
78
|
+
const queue = mock(Queue);
|
|
79
|
+
when(queue.name).thenReturn("default");
|
|
80
|
+
|
|
81
|
+
when(injector.getMany("bullmq:queue")).thenReturn([instance(queue)]);
|
|
82
|
+
|
|
83
|
+
const dispatcher = new JobDispatcher(instance(injector));
|
|
84
|
+
|
|
85
|
+
await dispatcher.dispatch(ExampleTestJob, {msg: "hello test"}, {jobId: 'ffeeaa'});
|
|
86
|
+
|
|
87
|
+
verify(
|
|
88
|
+
queue.add(
|
|
89
|
+
"example-job",
|
|
90
|
+
objectContaining({msg: "hello test"}),
|
|
91
|
+
objectContaining({
|
|
92
|
+
backoff: 69,
|
|
93
|
+
jobId: 'ffeeaa'
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
).once();
|
|
97
|
+
});
|
|
52
98
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {InjectorService, Service} from "@tsed/di";
|
|
2
2
|
import {JobMethods, type JobStore} from "../contracts";
|
|
3
3
|
import {Store, Type} from "@tsed/core";
|
|
4
|
-
import {Job as BullMQJob, Queue} from "bullmq";
|
|
4
|
+
import {Job as BullMQJob, JobsOptions, Queue} from "bullmq";
|
|
5
5
|
|
|
6
6
|
@Service()
|
|
7
7
|
export class JobDispatcher {
|
|
8
8
|
constructor(private readonly injector: InjectorService) {}
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line require-await
|
|
11
|
-
public async dispatch<T extends JobMethods>(job: Type<T>, payload: Parameters<T["handle"]>[0] = {}): Promise<BullMQJob> {
|
|
11
|
+
public async dispatch<T extends JobMethods>(job: Type<T>, payload: Parameters<T["handle"]>[0] = {}, options: JobsOptions = {}): Promise<BullMQJob> {
|
|
12
12
|
const store = Store.from(job).get<JobStore>("bullmq");
|
|
13
13
|
|
|
14
14
|
const queue = this.injector.getMany<Queue>("bullmq:queue").find((queue) => queue.name === store.queue);
|
|
@@ -17,6 +17,9 @@ export class JobDispatcher {
|
|
|
17
17
|
throw new Error(`Queue(${store.queue}) not defined`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
return queue.add(store.name, payload,
|
|
20
|
+
return queue.add(store.name, payload, {
|
|
21
|
+
...store.opts,
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
21
24
|
}
|
|
22
25
|
}
|