@alanszp/queue 12.0.2 → 12.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/package.json +7 -10
- package/.gitignore +0 -3
- package/.npmignore +0 -3
- package/node_modules/@alanszp/core/.gitignore +0 -3
- package/node_modules/@alanszp/core/.npmignore +0 -3
- package/node_modules/@alanszp/core/LICENSE +0 -21
- package/node_modules/@alanszp/core/dist/app/appIdentifier.d.ts +0 -1
- package/node_modules/@alanszp/core/dist/app/appIdentifier.js +0 -10
- package/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +0 -1
- package/node_modules/@alanszp/core/dist/app/index.d.ts +0 -1
- package/node_modules/@alanszp/core/dist/app/index.js +0 -18
- package/node_modules/@alanszp/core/dist/app/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/assignKey.d.ts +0 -2
- package/node_modules/@alanszp/core/dist/assignKey.js +0 -20
- package/node_modules/@alanszp/core/dist/assignKey.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/index.d.ts +0 -2
- package/node_modules/@alanszp/core/dist/editable/index.js +0 -19
- package/node_modules/@alanszp/core/dist/editable/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +0 -3
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +0 -26
- package/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +0 -1
- package/node_modules/@alanszp/core/dist/editable/types.d.ts +0 -6
- package/node_modules/@alanszp/core/dist/editable/types.js +0 -3
- package/node_modules/@alanszp/core/dist/editable/types.js.map +0 -1
- package/node_modules/@alanszp/core/dist/index.d.ts +0 -4
- package/node_modules/@alanszp/core/dist/index.js +0 -21
- package/node_modules/@alanszp/core/dist/index.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +0 -7
- package/node_modules/@alanszp/core/dist/lists/ListResult.js +0 -8
- package/node_modules/@alanszp/core/dist/lists/ListResult.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +0 -11
- package/node_modules/@alanszp/core/dist/lists/Orderable.js +0 -13
- package/node_modules/@alanszp/core/dist/lists/Orderable.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +0 -14
- package/node_modules/@alanszp/core/dist/lists/Paginable.js +0 -22
- package/node_modules/@alanszp/core/dist/lists/Paginable.js.map +0 -1
- package/node_modules/@alanszp/core/dist/lists/index.d.ts +0 -3
- package/node_modules/@alanszp/core/dist/lists/index.js +0 -20
- package/node_modules/@alanszp/core/dist/lists/index.js.map +0 -1
- package/node_modules/@alanszp/core/package.json +0 -25
- package/node_modules/@alanszp/core/tsconfig.json +0 -15
- package/node_modules/@types/node/LICENSE +0 -21
- package/node_modules/@types/node/README.md +0 -15
- package/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/assert.d.ts +0 -996
- package/node_modules/@types/node/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/buffer.d.ts +0 -2362
- package/node_modules/@types/node/child_process.d.ts +0 -1540
- package/node_modules/@types/node/cluster.d.ts +0 -432
- package/node_modules/@types/node/console.d.ts +0 -415
- package/node_modules/@types/node/constants.d.ts +0 -19
- package/node_modules/@types/node/crypto.d.ts +0 -4487
- package/node_modules/@types/node/dgram.d.ts +0 -596
- package/node_modules/@types/node/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/dns.d.ts +0 -809
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/domain.d.ts +0 -170
- package/node_modules/@types/node/events.d.ts +0 -879
- package/node_modules/@types/node/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/fs.d.ts +0 -4311
- package/node_modules/@types/node/globals.d.ts +0 -411
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/http.d.ts +0 -1887
- package/node_modules/@types/node/http2.d.ts +0 -2382
- package/node_modules/@types/node/https.d.ts +0 -550
- package/node_modules/@types/node/index.d.ts +0 -88
- package/node_modules/@types/node/inspector.d.ts +0 -2747
- package/node_modules/@types/node/module.d.ts +0 -315
- package/node_modules/@types/node/net.d.ts +0 -949
- package/node_modules/@types/node/os.d.ts +0 -478
- package/node_modules/@types/node/package.json +0 -229
- package/node_modules/@types/node/path.d.ts +0 -191
- package/node_modules/@types/node/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/process.d.ts +0 -1561
- package/node_modules/@types/node/punycode.d.ts +0 -117
- package/node_modules/@types/node/querystring.d.ts +0 -141
- package/node_modules/@types/node/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/readline.d.ts +0 -539
- package/node_modules/@types/node/repl.d.ts +0 -430
- package/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/stream/web.d.ts +0 -366
- package/node_modules/@types/node/stream.d.ts +0 -1701
- package/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/test.d.ts +0 -1465
- package/node_modules/@types/node/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/timers.d.ts +0 -240
- package/node_modules/@types/node/tls.d.ts +0 -1210
- package/node_modules/@types/node/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4487
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -596
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -545
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -879
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1239
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4311
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -411
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1887
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -315
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -478
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -645
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1561
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -366
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1465
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2183
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -764
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -903
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -179
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/@types/node/tty.d.ts +0 -208
- package/node_modules/@types/node/url.d.ts +0 -927
- package/node_modules/@types/node/util.d.ts +0 -2183
- package/node_modules/@types/node/v8.d.ts +0 -764
- package/node_modules/@types/node/vm.d.ts +0 -903
- package/node_modules/@types/node/wasi.d.ts +0 -179
- package/node_modules/@types/node/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/zlib.d.ts +0 -517
- package/src/connectionManager.ts +0 -68
- package/src/errors/JobCannotBePromotedError.ts +0 -25
- package/src/errors/JobNotFoundError.ts +0 -20
- package/src/index.ts +0 -9
- package/src/jobsManagement/commands/asyncCreationCommands.ts +0 -58
- package/src/jobsManagement/commands/getCommands.ts +0 -57
- package/src/jobsManagement/commands/workerHealthCommand.ts +0 -10
- package/src/jobsManagement/index.ts +0 -6
- package/src/jobsManagement/inputs/CreateAsyncJobInput.ts +0 -36
- package/src/jobsManagement/inputs/GetJobInput.ts +0 -17
- package/src/jobsManagement/inputs/SearchJobsInput.ts +0 -45
- package/src/queue/createQueue.ts +0 -22
- package/src/queue/queue.ts +0 -195
- package/src/queue/queueRepository.ts +0 -27
- package/src/reporter/totalCount/ITotalCountReporter.ts +0 -5
- package/src/reporter/totalCount/JobTotalCountReporter.ts +0 -37
- package/src/reporter/totalCount/MockTotalCountReporter.ts +0 -20
- package/src/runner.ts +0 -16
- package/src/shutdownQueue.ts +0 -12
- package/src/types.ts +0 -38
- package/src/worker/worker.ts +0 -187
- package/src/worker/workerRepository.ts +0 -83
- package/src/wrappers/withContext.ts +0 -29
package/src/worker/worker.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "@alanszp/logger";
|
|
2
|
-
import { ConnectionManager } from "../connectionManager";
|
|
3
|
-
import {
|
|
4
|
-
JobData,
|
|
5
|
-
Job,
|
|
6
|
-
RawWorker,
|
|
7
|
-
WorkerOptions,
|
|
8
|
-
JobReturnValue,
|
|
9
|
-
} from "../types";
|
|
10
|
-
import { SharedContext } from "@alanszp/shared-context";
|
|
11
|
-
import { Audit } from "@alanszp/audit";
|
|
12
|
-
import { withContext } from "../wrappers/withContext";
|
|
13
|
-
|
|
14
|
-
export interface WorkerStatus {
|
|
15
|
-
running: boolean;
|
|
16
|
-
paused: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface WorkerSetup {
|
|
20
|
-
queueName: string;
|
|
21
|
-
workerOptions?: WorkerOptions;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface WorkerContext {
|
|
25
|
-
sharedContext: SharedContext;
|
|
26
|
-
baseLogger: ILogger;
|
|
27
|
-
audit: Audit;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// optional methods
|
|
31
|
-
|
|
32
|
-
interface Worker<Data = JobData, ReturnValue = JobReturnValue> {
|
|
33
|
-
handleJobFailed?(
|
|
34
|
-
job: Job<Data, ReturnValue>,
|
|
35
|
-
error: Error
|
|
36
|
-
): Promise<void> | void;
|
|
37
|
-
handleJobCompleted?(job: Job<Data, ReturnValue>): Promise<void> | void;
|
|
38
|
-
handleJobError?(error: Error): Promise<void> | void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type QueueName = { name: string; prefix: string; namespace: string };
|
|
42
|
-
|
|
43
|
-
const BULL_PREFIX = "b";
|
|
44
|
-
|
|
45
|
-
abstract class Worker<Data = JobData, ReturnValue = unknown> {
|
|
46
|
-
private _worker: RawWorker;
|
|
47
|
-
|
|
48
|
-
private _queue: QueueName;
|
|
49
|
-
|
|
50
|
-
private getLogger: () => ILogger;
|
|
51
|
-
|
|
52
|
-
constructor() {
|
|
53
|
-
const { queueName: name, workerOptions } = this.setup();
|
|
54
|
-
|
|
55
|
-
const connectionManager = ConnectionManager.getInstance();
|
|
56
|
-
this.getLogger = connectionManager.getLogger;
|
|
57
|
-
|
|
58
|
-
const prefix = connectionManager.getServiceName();
|
|
59
|
-
this._queue = { name, prefix, namespace: BULL_PREFIX };
|
|
60
|
-
this._worker = new RawWorker<Data, ReturnValue>(name, this.processJob(), {
|
|
61
|
-
autorun: false,
|
|
62
|
-
connection: connectionManager.getConnection(),
|
|
63
|
-
prefix: `{${prefix}}:${BULL_PREFIX}`,
|
|
64
|
-
...workerOptions,
|
|
65
|
-
});
|
|
66
|
-
this.getLogger().info("worker.ready", { queue: this.queueFullName });
|
|
67
|
-
|
|
68
|
-
this.registerHooks();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Handle job
|
|
72
|
-
abstract process(job: Job<Data, ReturnValue>): Promise<ReturnValue>;
|
|
73
|
-
|
|
74
|
-
abstract setup(): WorkerSetup;
|
|
75
|
-
|
|
76
|
-
abstract getContext(): WorkerContext;
|
|
77
|
-
|
|
78
|
-
public close(): Promise<void> {
|
|
79
|
-
return this.worker.close();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public get status(): WorkerStatus {
|
|
83
|
-
return { running: this.worker.isRunning(), paused: this.worker.isPaused() };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public get id(): RawWorker["id"] {
|
|
87
|
-
return this.worker.id;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private processJob(): (job: Job<Data, ReturnValue>) => Promise<ReturnValue> {
|
|
91
|
-
return withContext(this.queueFullName, this.getContext(), async (job) => {
|
|
92
|
-
this.getLogger().info(`worker.process.job_received`, {
|
|
93
|
-
queue: this.queueFullName,
|
|
94
|
-
job,
|
|
95
|
-
});
|
|
96
|
-
return this.process(job);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async processFailed(
|
|
101
|
-
job: Job<Data, ReturnValue>,
|
|
102
|
-
error: Error
|
|
103
|
-
): Promise<void> {
|
|
104
|
-
this.getLogger().warn("worker.job.failed", {
|
|
105
|
-
queue: this.queueFullName,
|
|
106
|
-
job,
|
|
107
|
-
error,
|
|
108
|
-
});
|
|
109
|
-
if (this.handleJobFailed) {
|
|
110
|
-
await this.handleJobFailed(job, error);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async processCompleted(
|
|
115
|
-
job: Job<Data, ReturnValue>,
|
|
116
|
-
returnValue: ReturnValue
|
|
117
|
-
): Promise<void> {
|
|
118
|
-
this.getLogger().info("worker.job.completed", {
|
|
119
|
-
queue: this.queueFullName,
|
|
120
|
-
job,
|
|
121
|
-
returnValue,
|
|
122
|
-
});
|
|
123
|
-
if (this.handleJobCompleted) {
|
|
124
|
-
await this.handleJobCompleted(job);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async processError(error: Error): Promise<void> {
|
|
129
|
-
this.getLogger().error("worker.job.unhandled_exception", {
|
|
130
|
-
queue: this.queueFullName,
|
|
131
|
-
error,
|
|
132
|
-
});
|
|
133
|
-
if (this.handleJobError) {
|
|
134
|
-
await this.handleJobError(error);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async run(): Promise<void> {
|
|
139
|
-
try {
|
|
140
|
-
this.getLogger().info("worker.run.starting", {
|
|
141
|
-
queue: this.queueFullName,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await this.worker.run();
|
|
145
|
-
this.getLogger().info("worker.run.started", {
|
|
146
|
-
queue: this.queueFullName,
|
|
147
|
-
});
|
|
148
|
-
} catch (error: unknown) {
|
|
149
|
-
this.getLogger().error("worker.run.error", {
|
|
150
|
-
queue: this.queueFullName,
|
|
151
|
-
error,
|
|
152
|
-
});
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
protected registerHooks(): void {
|
|
158
|
-
// on error: handle unhandled exceptions
|
|
159
|
-
this.worker.on("error", (error: Error) => this.processError(error));
|
|
160
|
-
// on completed: allow to do something else after a job is completed
|
|
161
|
-
this.worker.on(
|
|
162
|
-
"completed",
|
|
163
|
-
(job: Job<Data, ReturnValue>, result: ReturnValue) =>
|
|
164
|
-
this.processCompleted(job, result)
|
|
165
|
-
);
|
|
166
|
-
// on failed: when the process fails with an exception it is possible to listen for the "failed" event
|
|
167
|
-
this.worker.on("failed", (job: Job<Data, ReturnValue>, error: Error) =>
|
|
168
|
-
this.processFailed(job, error)
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
protected get worker(): RawWorker {
|
|
173
|
-
return this._worker;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
get queueFullName(): string {
|
|
177
|
-
const { name, prefix, namespace } = this._queue;
|
|
178
|
-
return `{${prefix}}:${namespace}:${name}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
get queueName(): string {
|
|
182
|
-
return this._queue.name;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// this export is required for merging optional methods interface into abstract class
|
|
187
|
-
export { Worker };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "@alanszp/logger";
|
|
2
|
-
import { compact, isEmpty } from "lodash";
|
|
3
|
-
import { ConnectionManager } from "../connectionManager";
|
|
4
|
-
import { Worker, WorkerStatus } from "./worker";
|
|
5
|
-
|
|
6
|
-
export type WorkerStatusWithId = { status: WorkerStatus } & { id: string };
|
|
7
|
-
interface WorkerClass {
|
|
8
|
-
new (): Worker;
|
|
9
|
-
}
|
|
10
|
-
type QueueWorkerMap = Record<string, WorkerClass>;
|
|
11
|
-
|
|
12
|
-
export class WorkerRepository {
|
|
13
|
-
private _workers: QueueWorkerMap;
|
|
14
|
-
|
|
15
|
-
private _activeWorkers: Worker[];
|
|
16
|
-
|
|
17
|
-
private static _instance: WorkerRepository;
|
|
18
|
-
|
|
19
|
-
private getLogger: () => ILogger;
|
|
20
|
-
|
|
21
|
-
private constructor() {
|
|
22
|
-
this._workers = {};
|
|
23
|
-
this._activeWorkers = [];
|
|
24
|
-
this.getLogger = ConnectionManager.getInstance().getLogger;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public static get Instance(): WorkerRepository {
|
|
28
|
-
if (this._instance) {
|
|
29
|
-
return this._instance;
|
|
30
|
-
}
|
|
31
|
-
this._instance = new this();
|
|
32
|
-
return this._instance;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public registerWorker(
|
|
36
|
-
queueName: string,
|
|
37
|
-
workerClass: WorkerClass
|
|
38
|
-
): WorkerRepository {
|
|
39
|
-
Object.assign(this.workers, { [queueName]: workerClass });
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getWorkersByQueues(queueNames: string[]): Worker[] {
|
|
44
|
-
if (isEmpty(this.workers)) {
|
|
45
|
-
this.getLogger().warn("worker_repository.queue_worker_map_is_empty");
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return compact(
|
|
50
|
-
queueNames.map((queueName: string) => {
|
|
51
|
-
if (this.workers[queueName]) {
|
|
52
|
-
const worker = new this.workers[queueName]();
|
|
53
|
-
// assuming this method is only called in a context for running them
|
|
54
|
-
this._activeWorkers.push(worker);
|
|
55
|
-
return worker;
|
|
56
|
-
}
|
|
57
|
-
this.getLogger().warn("worker_repository.invalid_queue_name", {
|
|
58
|
-
queueName,
|
|
59
|
-
});
|
|
60
|
-
return null;
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getWorkerStatuses(): WorkerStatusWithId[] {
|
|
66
|
-
return this.activeWorkers.map((worker) => ({
|
|
67
|
-
id: worker.id,
|
|
68
|
-
status: worker.status,
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public getCloseConnections(): Promise<void>[] {
|
|
73
|
-
return this.activeWorkers.map((worker) => worker.close());
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private get workers(): QueueWorkerMap {
|
|
77
|
-
return this._workers;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private get activeWorkers(): Worker[] {
|
|
81
|
-
return this._activeWorkers;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
-
import { appIdentifier } from "@alanszp/core";
|
|
3
|
-
import { Job, JobData } from "bullmq";
|
|
4
|
-
import { WorkerContext } from "../worker/worker";
|
|
5
|
-
import { JobReturnValue } from "../types";
|
|
6
|
-
import { compact } from "lodash";
|
|
7
|
-
|
|
8
|
-
export function withContext<T = JobData, ReturnValue = JobReturnValue>(
|
|
9
|
-
queueName: string,
|
|
10
|
-
workerContext: WorkerContext,
|
|
11
|
-
executor: (job: Job<T>) => Promise<ReturnValue>
|
|
12
|
-
): (job: Job<T>) => Promise<ReturnValue> {
|
|
13
|
-
return (job) => {
|
|
14
|
-
const { lid, lch } = job.data as { lid?: string; lch?: string };
|
|
15
|
-
return workerContext.sharedContext.run(
|
|
16
|
-
async () => {
|
|
17
|
-
return executor(job);
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
logger: workerContext.baseLogger,
|
|
21
|
-
audit: workerContext.audit.withState(),
|
|
22
|
-
lifecycleId: lid || createId(),
|
|
23
|
-
lifecycleChain:
|
|
24
|
-
compact([lch, `wkr:${queueName}`]).join(",") || appIdentifier(),
|
|
25
|
-
contextId: createId(),
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
}
|