@volontariapp/workers 0.1.0-snap-b032dae → 0.1.0-snap-a134190
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/dist/base.worker.d.ts +14 -0
- package/dist/base.worker.d.ts.map +1 -0
- package/dist/base.worker.js +51 -0
- package/dist/base.worker.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/worker-config.types.d.ts +14 -0
- package/dist/types/worker-config.types.d.ts.map +1 -0
- package/dist/types/worker-config.types.js +2 -0
- package/dist/types/worker-config.types.js.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Job } from 'bullmq';
|
|
2
|
+
import { Logger } from '@volontariapp/logger';
|
|
3
|
+
import type { WorkerConfig } from './types/worker-config.types.js';
|
|
4
|
+
export declare abstract class BaseWorker<TData extends Record<string, unknown>> {
|
|
5
|
+
protected readonly config: WorkerConfig;
|
|
6
|
+
private readonly worker;
|
|
7
|
+
protected readonly logger: Logger;
|
|
8
|
+
protected readonly workerId: string;
|
|
9
|
+
constructor(config: WorkerConfig);
|
|
10
|
+
private registerEvents;
|
|
11
|
+
protected abstract processJob(job: Job<TData, void>): Promise<void>;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=base.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.worker.d.ts","sourceRoot":"","sources":["../src/base.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE,8BAAsB,UAAU,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAKxD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY;IAJnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,EAAE,YAAY;IAgBnD,OAAO,CAAC,cAAc;IA2BtB,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Worker } from 'bullmq';
|
|
2
|
+
import { Logger } from '@volontariapp/logger';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
4
|
+
export class BaseWorker {
|
|
5
|
+
config;
|
|
6
|
+
worker;
|
|
7
|
+
logger;
|
|
8
|
+
workerId;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.workerId = hostname();
|
|
12
|
+
this.logger = new Logger({ context: this.constructor.name });
|
|
13
|
+
this.worker = new Worker(config.queueName, (job) => this.processJob(job), {
|
|
14
|
+
connection: config.connection,
|
|
15
|
+
concurrency: config.concurrency ?? 1,
|
|
16
|
+
});
|
|
17
|
+
this.registerEvents();
|
|
18
|
+
}
|
|
19
|
+
registerEvents() {
|
|
20
|
+
this.worker.on('completed', (job) => {
|
|
21
|
+
this.logger.info(`Job completed`, {
|
|
22
|
+
jobId: job.id,
|
|
23
|
+
jobName: job.name,
|
|
24
|
+
workerId: this.workerId,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
this.worker.on('failed', (job, error) => {
|
|
28
|
+
this.logger.error(`Job failed`, {
|
|
29
|
+
jobId: job?.id,
|
|
30
|
+
jobName: job?.name,
|
|
31
|
+
workerId: this.workerId,
|
|
32
|
+
error,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
this.worker.on('error', (error) => {
|
|
36
|
+
this.logger.error(`Worker error`, {
|
|
37
|
+
workerId: this.workerId,
|
|
38
|
+
queue: this.config.queueName,
|
|
39
|
+
error,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async close() {
|
|
44
|
+
this.logger.info(`Worker closing`, {
|
|
45
|
+
workerId: this.workerId,
|
|
46
|
+
queue: this.config.queueName,
|
|
47
|
+
});
|
|
48
|
+
await this.worker.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=base.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.worker.js","sourceRoot":"","sources":["../src/base.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,MAAM,OAAgB,UAAU;IAKC;IAJd,MAAM,CAAsB;IAC1B,MAAM,CAAS;IACf,QAAQ,CAAS;IAEpC,YAA+B,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACjD,IAAI,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACtB,MAAM,CAAC,SAAS,EAChB,CAAC,GAAqB,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAC/C;YACE,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC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/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { BaseWorker } from './base.worker.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface WorkerConnectionConfig {
|
|
2
|
+
host: string;
|
|
3
|
+
port: number;
|
|
4
|
+
db?: number;
|
|
5
|
+
maxRetriesPerRequest?: number | null;
|
|
6
|
+
enableReadyCheck?: boolean;
|
|
7
|
+
enableOfflineQueue?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkerConfig {
|
|
10
|
+
queueName: string;
|
|
11
|
+
concurrency?: number;
|
|
12
|
+
connection: WorkerConnectionConfig;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=worker-config.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-config.types.d.ts","sourceRoot":"","sources":["../../src/types/worker-config.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,sBAAsB,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-config.types.js","sourceRoot":"","sources":["../../src/types/worker-config.types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volontariapp/workers",
|
|
3
|
-
"version": "0.1.0-snap-
|
|
3
|
+
"version": "0.1.0-snap-a134190",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -32,7 +32,12 @@
|
|
|
32
32
|
"lint": "eslint src/",
|
|
33
33
|
"test": "echo \"No tests yet\""
|
|
34
34
|
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@volontariapp/logger": "0.2.3",
|
|
37
|
+
"bullmq": "^5.76.5"
|
|
38
|
+
},
|
|
35
39
|
"devDependencies": {
|
|
40
|
+
"@types/node": "^24.0.0",
|
|
36
41
|
"typescript": "5.7.3"
|
|
37
42
|
}
|
|
38
43
|
}
|