@lowerdeck/queue 1.0.1 → 1.0.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/.turbo/turbo-build.log +23 -8
- package/CHANGELOG.md +16 -0
- package/dist/drivers/bullmq.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +7 -4
- package/src/drivers/bullmq.ts +82 -44
- package/src/index.ts +7 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowerdeck/queue",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -24,9 +24,12 @@
|
|
|
24
24
|
"build": "microbundle"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lowerdeck/delay": "^1.0.
|
|
28
|
-
"@lowerdeck/
|
|
29
|
-
"@lowerdeck/
|
|
27
|
+
"@lowerdeck/delay": "^1.0.3",
|
|
28
|
+
"@lowerdeck/execution-context": "^1.0.1",
|
|
29
|
+
"@lowerdeck/id": "^1.0.4",
|
|
30
|
+
"@lowerdeck/memo": "^1.0.3",
|
|
31
|
+
"@lowerdeck/redis": "^1.0.2",
|
|
32
|
+
"@lowerdeck/sentry": "^1.0.1",
|
|
30
33
|
"bullmq": "^5.66.0",
|
|
31
34
|
"superjson": "^2.2.6"
|
|
32
35
|
},
|
package/src/drivers/bullmq.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { delay } from '@lowerdeck/delay';
|
|
2
|
+
import {
|
|
3
|
+
createExecutionContext,
|
|
4
|
+
ExecutionContext,
|
|
5
|
+
provideExecutionContext,
|
|
6
|
+
withExecutionContextOptional
|
|
7
|
+
} from '@lowerdeck/execution-context';
|
|
8
|
+
import { generateSnowflakeId } from '@lowerdeck/id';
|
|
2
9
|
import { memo } from '@lowerdeck/memo';
|
|
3
10
|
import { parseRedisUrl } from '@lowerdeck/redis';
|
|
11
|
+
import { getSentry } from '@lowerdeck/sentry';
|
|
4
12
|
import {
|
|
5
13
|
DeduplicationOptions,
|
|
6
14
|
JobsOptions,
|
|
@@ -16,6 +24,8 @@ import { IQueue } from '../types';
|
|
|
16
24
|
// @ts-ignore
|
|
17
25
|
import SuperJson from 'superjson';
|
|
18
26
|
|
|
27
|
+
let Sentry = getSentry();
|
|
28
|
+
|
|
19
29
|
let log = (...any: any[]) => console.log('[QUEUE MANAGER]:', ...any);
|
|
20
30
|
|
|
21
31
|
let anyQueueStartedRef = { started: false };
|
|
@@ -57,16 +67,20 @@ export let createBullMqQueue = <JobData>(
|
|
|
57
67
|
name: opts.name,
|
|
58
68
|
|
|
59
69
|
add: async (payload, opts) => {
|
|
60
|
-
let job = await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
let job = await withExecutionContextOptional(
|
|
71
|
+
async ctx =>
|
|
72
|
+
await queue.add(
|
|
73
|
+
'j' as any,
|
|
74
|
+
{
|
|
75
|
+
payload: SuperJson.serialize(payload),
|
|
76
|
+
$$execution_context$$: ctx
|
|
77
|
+
} as any,
|
|
78
|
+
{
|
|
79
|
+
delay: opts?.delay,
|
|
80
|
+
jobId: opts?.id,
|
|
81
|
+
deduplication: opts?.deduplication
|
|
82
|
+
}
|
|
83
|
+
)
|
|
70
84
|
);
|
|
71
85
|
|
|
72
86
|
return {
|
|
@@ -78,41 +92,47 @@ export let createBullMqQueue = <JobData>(
|
|
|
78
92
|
},
|
|
79
93
|
|
|
80
94
|
addMany: async (payloads, opts) => {
|
|
81
|
-
await
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
await withExecutionContextOptional(async ctx => {
|
|
96
|
+
await queue.addBulk(
|
|
97
|
+
payloads.map(
|
|
98
|
+
payload =>
|
|
99
|
+
({
|
|
100
|
+
name: 'j',
|
|
101
|
+
data: {
|
|
102
|
+
payload: SuperJson.serialize(payload),
|
|
103
|
+
$$execution_context$$: ctx
|
|
104
|
+
},
|
|
105
|
+
opts: {
|
|
106
|
+
delay: opts?.delay,
|
|
107
|
+
jobId: opts?.id,
|
|
108
|
+
deduplication: opts?.deduplication
|
|
109
|
+
}
|
|
110
|
+
}) as any
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
});
|
|
97
114
|
},
|
|
98
115
|
|
|
99
116
|
addManyWithOps: async payloads => {
|
|
100
|
-
await
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
await withExecutionContextOptional(async ctx => {
|
|
118
|
+
await queue.addBulk(
|
|
119
|
+
payloads.map(
|
|
120
|
+
payload =>
|
|
121
|
+
({
|
|
122
|
+
name: 'j',
|
|
123
|
+
data: {
|
|
124
|
+
payload: SuperJson.serialize(payload.data),
|
|
125
|
+
$$execution_context$$: ctx
|
|
126
|
+
},
|
|
127
|
+
opts: {
|
|
128
|
+
delay: payload.opts?.delay,
|
|
129
|
+
jobId: payload.opts?.id,
|
|
130
|
+
deduplication: payload.opts?.deduplication
|
|
131
|
+
}
|
|
132
|
+
}) as any
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
});
|
|
116
136
|
},
|
|
117
137
|
|
|
118
138
|
process: cb => {
|
|
@@ -144,13 +164,31 @@ export let createBullMqQueue = <JobData>(
|
|
|
144
164
|
payload = data.payload;
|
|
145
165
|
}
|
|
146
166
|
|
|
147
|
-
|
|
167
|
+
let parentExecutionContext = (data as any)
|
|
168
|
+
.$$execution_context$$ as ExecutionContext;
|
|
169
|
+
while (
|
|
170
|
+
parentExecutionContext &&
|
|
171
|
+
parentExecutionContext.type == 'job' &&
|
|
172
|
+
parentExecutionContext.parent
|
|
173
|
+
)
|
|
174
|
+
parentExecutionContext = parentExecutionContext.parent;
|
|
175
|
+
|
|
176
|
+
await provideExecutionContext(
|
|
177
|
+
createExecutionContext({
|
|
178
|
+
type: 'job',
|
|
179
|
+
contextId: job.id ?? generateSnowflakeId(),
|
|
180
|
+
queue: opts.name,
|
|
181
|
+
parent: parentExecutionContext
|
|
182
|
+
}),
|
|
183
|
+
() => cb(payload as any, job)
|
|
184
|
+
);
|
|
148
185
|
} catch (e: any) {
|
|
149
186
|
if (e instanceof QueueRetryError) {
|
|
150
187
|
await delay(1000);
|
|
151
188
|
throw e;
|
|
152
189
|
} else {
|
|
153
|
-
|
|
190
|
+
Sentry.captureException(e);
|
|
191
|
+
console.error(e);
|
|
154
192
|
throw e;
|
|
155
193
|
}
|
|
156
194
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,17 +14,14 @@ export let createQueue = <JobData>(opts: { driver?: 'bullmq' } & BullMqCreateOpt
|
|
|
14
14
|
}
|
|
15
15
|
seenNames.add(opts.name);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
jobOpts: opts.jobOpts,
|
|
21
|
-
queueOpts: opts.queueOpts,
|
|
22
|
-
workerOpts: opts.workerOpts,
|
|
23
|
-
redisUrl: opts.redisUrl
|
|
24
|
-
});
|
|
25
|
-
}
|
|
17
|
+
return createBullMqQueue<JobData>({
|
|
18
|
+
name: opts.name,
|
|
19
|
+
redisUrl: opts.redisUrl,
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
jobOpts: opts.jobOpts,
|
|
22
|
+
queueOpts: opts.queueOpts,
|
|
23
|
+
workerOpts: opts.workerOpts
|
|
24
|
+
});
|
|
28
25
|
};
|
|
29
26
|
|
|
30
27
|
export let combineQueueProcessors = (opts: IQueueProcessor[]): IQueueProcessor => {
|