light-async-queue 1.0.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/LICENSE +21 -0
- package/README.md +385 -0
- package/dist/src/dlq/DeadLetterQueue.d.ts +34 -0
- package/dist/src/dlq/DeadLetterQueue.d.ts.map +1 -0
- package/dist/src/dlq/DeadLetterQueue.js +60 -0
- package/dist/src/dlq/DeadLetterQueue.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/queue/Backoff.d.ts +24 -0
- package/dist/src/queue/Backoff.d.ts.map +1 -0
- package/dist/src/queue/Backoff.js +37 -0
- package/dist/src/queue/Backoff.js.map +1 -0
- package/dist/src/queue/Job.d.ts +44 -0
- package/dist/src/queue/Job.d.ts.map +1 -0
- package/dist/src/queue/Job.js +89 -0
- package/dist/src/queue/Job.js.map +1 -0
- package/dist/src/queue/Queue.d.ts +67 -0
- package/dist/src/queue/Queue.d.ts.map +1 -0
- package/dist/src/queue/Queue.js +261 -0
- package/dist/src/queue/Queue.js.map +1 -0
- package/dist/src/queue/Scheduler.d.ts +30 -0
- package/dist/src/queue/Scheduler.d.ts.map +1 -0
- package/dist/src/queue/Scheduler.js +62 -0
- package/dist/src/queue/Scheduler.js.map +1 -0
- package/dist/src/storage/FileStore.d.ts +55 -0
- package/dist/src/storage/FileStore.d.ts.map +1 -0
- package/dist/src/storage/FileStore.js +247 -0
- package/dist/src/storage/FileStore.js.map +1 -0
- package/dist/src/storage/MemoryStore.d.ts +21 -0
- package/dist/src/storage/MemoryStore.d.ts.map +1 -0
- package/dist/src/storage/MemoryStore.js +55 -0
- package/dist/src/storage/MemoryStore.js.map +1 -0
- package/dist/src/types.d.ts +126 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/worker/Worker.d.ts +36 -0
- package/dist/src/worker/Worker.d.ts.map +1 -0
- package/dist/src/worker/Worker.js +170 -0
- package/dist/src/worker/Worker.js.map +1 -0
- package/dist/src/worker/childProcessor.d.ts +2 -0
- package/dist/src/worker/childProcessor.d.ts.map +1 -0
- package/dist/src/worker/childProcessor.js +70 -0
- package/dist/src/worker/childProcessor.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
/**
|
|
7
|
+
* Worker manager that handles job execution in isolated child processes
|
|
8
|
+
*/
|
|
9
|
+
export class Worker {
|
|
10
|
+
processor;
|
|
11
|
+
childProcess;
|
|
12
|
+
isReady;
|
|
13
|
+
currentJobId;
|
|
14
|
+
constructor(processor) {
|
|
15
|
+
this.processor = processor;
|
|
16
|
+
this.childProcess = null;
|
|
17
|
+
this.isReady = false;
|
|
18
|
+
this.currentJobId = null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the worker by forking a child process
|
|
22
|
+
*/
|
|
23
|
+
async initialize() {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const childProcessorPath = join(__dirname, 'childProcessor.js');
|
|
26
|
+
this.childProcess = fork(childProcessorPath, [], {
|
|
27
|
+
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
|
|
28
|
+
});
|
|
29
|
+
// Handle ready signal from child
|
|
30
|
+
const readyHandler = (message) => {
|
|
31
|
+
if (message.type === 'ready') {
|
|
32
|
+
this.isReady = true;
|
|
33
|
+
this.childProcess?.off('message', readyHandler);
|
|
34
|
+
// Send processor function to child
|
|
35
|
+
this.sendProcessorToChild()
|
|
36
|
+
.then(() => resolve())
|
|
37
|
+
.catch(reject);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.childProcess.on('message', readyHandler);
|
|
41
|
+
// Handle child process errors
|
|
42
|
+
this.childProcess.on('error', (error) => {
|
|
43
|
+
console.error('[Worker] Child process error:', error);
|
|
44
|
+
reject(error);
|
|
45
|
+
});
|
|
46
|
+
// Handle unexpected exit during initialization
|
|
47
|
+
this.childProcess.on('exit', (code, signal) => {
|
|
48
|
+
if (!this.isReady) {
|
|
49
|
+
reject(new Error(`Child process exited during initialization: code=${code}, signal=${signal}`));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// Timeout after 5 seconds
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
if (!this.isReady) {
|
|
55
|
+
reject(new Error('Worker initialization timeout'));
|
|
56
|
+
}
|
|
57
|
+
}, 5000);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Send the processor function to the child process
|
|
62
|
+
*/
|
|
63
|
+
async sendProcessorToChild() {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
if (!this.childProcess) {
|
|
66
|
+
reject(new Error('Child process not initialized'));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Convert processor function to string
|
|
70
|
+
const processorCode = this.processor.toString();
|
|
71
|
+
this.childProcess.send({ type: 'setProcessor', code: processorCode }, (error) => {
|
|
72
|
+
if (error) {
|
|
73
|
+
reject(error);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolve();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Execute a job in the child process
|
|
83
|
+
*/
|
|
84
|
+
async execute(job) {
|
|
85
|
+
if (!this.childProcess || !this.isReady) {
|
|
86
|
+
throw new Error('Worker not initialized');
|
|
87
|
+
}
|
|
88
|
+
if (this.currentJobId) {
|
|
89
|
+
throw new Error('Worker is already processing a job');
|
|
90
|
+
}
|
|
91
|
+
this.currentJobId = job.id;
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
if (!this.childProcess) {
|
|
94
|
+
reject(new Error('Child process not available'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Set up message handler for result
|
|
98
|
+
const messageHandler = (message) => {
|
|
99
|
+
if (message.type === 'result' && message.jobId === job.id) {
|
|
100
|
+
this.childProcess?.off('message', messageHandler);
|
|
101
|
+
this.currentJobId = null;
|
|
102
|
+
if (message.result.success) {
|
|
103
|
+
resolve({
|
|
104
|
+
success: true,
|
|
105
|
+
result: message.result.result,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
resolve({
|
|
110
|
+
success: false,
|
|
111
|
+
error: message.result.error,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
this.childProcess.on('message', messageHandler);
|
|
117
|
+
// Handle child process crash
|
|
118
|
+
const exitHandler = (code, signal) => {
|
|
119
|
+
if (this.currentJobId === job.id) {
|
|
120
|
+
this.childProcess?.off('exit', exitHandler);
|
|
121
|
+
this.currentJobId = null;
|
|
122
|
+
this.isReady = false;
|
|
123
|
+
resolve({
|
|
124
|
+
success: false,
|
|
125
|
+
error: `Worker crashed: code=${code}, signal=${signal}`,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
this.childProcess.once('exit', exitHandler);
|
|
130
|
+
// Send job to child process
|
|
131
|
+
this.childProcess.send({
|
|
132
|
+
type: 'execute',
|
|
133
|
+
job,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Check if worker is currently processing a job
|
|
139
|
+
*/
|
|
140
|
+
isBusy() {
|
|
141
|
+
return this.currentJobId !== null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Terminate the worker
|
|
145
|
+
*/
|
|
146
|
+
async terminate() {
|
|
147
|
+
if (this.childProcess) {
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
if (!this.childProcess) {
|
|
150
|
+
resolve();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.childProcess.once('exit', () => {
|
|
154
|
+
this.childProcess = null;
|
|
155
|
+
this.isReady = false;
|
|
156
|
+
this.currentJobId = null;
|
|
157
|
+
resolve();
|
|
158
|
+
});
|
|
159
|
+
this.childProcess.kill();
|
|
160
|
+
// Force kill after 5 seconds
|
|
161
|
+
setTimeout(() => {
|
|
162
|
+
if (this.childProcess) {
|
|
163
|
+
this.childProcess.kill('SIGKILL');
|
|
164
|
+
}
|
|
165
|
+
}, 5000);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=Worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Worker.js","sourceRoot":"","sources":["../../../src/worker/Worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,MAAM;IACT,SAAS,CAAe;IACxB,YAAY,CAAsB;IAClC,OAAO,CAAU;IACjB,YAAY,CAAgB;IAEpC,YAAY,SAAuB;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAA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H,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"childProcessor.d.ts","sourceRoot":"","sources":["../../../src/worker/childProcessor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Child process script that executes jobs in isolation
|
|
3
|
+
* Communicates with parent via IPC
|
|
4
|
+
*/
|
|
5
|
+
// Store the job processor function
|
|
6
|
+
let processorFn = null;
|
|
7
|
+
/**
|
|
8
|
+
* Handle messages from parent process
|
|
9
|
+
*/
|
|
10
|
+
process.on('message', async (message) => {
|
|
11
|
+
if (message.type === 'execute') {
|
|
12
|
+
const { job } = message;
|
|
13
|
+
try {
|
|
14
|
+
// Execute the job processor
|
|
15
|
+
if (!processorFn) {
|
|
16
|
+
throw new Error('Processor function not set');
|
|
17
|
+
}
|
|
18
|
+
const result = await processorFn(job);
|
|
19
|
+
const response = {
|
|
20
|
+
type: 'result',
|
|
21
|
+
jobId: job.id,
|
|
22
|
+
result: {
|
|
23
|
+
success: true,
|
|
24
|
+
result,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
process.send(response);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const response = {
|
|
31
|
+
type: 'result',
|
|
32
|
+
jobId: job.id,
|
|
33
|
+
result: {
|
|
34
|
+
success: false,
|
|
35
|
+
error: error instanceof Error ? error.message : String(error),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
process.send(response);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (message.type === 'setProcessor') {
|
|
42
|
+
// Receive the processor function code as a string and evaluate it
|
|
43
|
+
// This is sent from the parent during worker initialization
|
|
44
|
+
try {
|
|
45
|
+
const processorCode = message.code;
|
|
46
|
+
processorFn = eval(`(${processorCode})`);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('Failed to set processor function:', error);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Handle uncaught errors
|
|
56
|
+
*/
|
|
57
|
+
process.on('uncaughtException', (error) => {
|
|
58
|
+
console.error('Uncaught exception in worker:', error);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
61
|
+
process.on('unhandledRejection', (reason) => {
|
|
62
|
+
console.error('Unhandled rejection in worker:', reason);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
65
|
+
// Signal ready
|
|
66
|
+
if (process.send) {
|
|
67
|
+
process.send({ type: 'ready' });
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=childProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"childProcessor.js","sourceRoot":"","sources":["../../../src/worker/childProcessor.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,mCAAmC;AACnC,IAAI,WAAW,GAAgD,IAAI,CAAC;AAEpE;;GAEG;AACH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAsB,EAAE,EAAE;IACrD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAExB,IAAI,CAAC;YACH,4BAA4B;YAC5B,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAChD,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;YAEtC,MAAM,QAAQ,GAAmB;gBAC/B,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,GAAG,CAAC,EAAE;gBACb,MAAM,EAAE;oBACN,OAAO,EAAE,IAAI;oBACb,MAAM;iBACP;aACF,CAAC;YAEF,OAAO,CAAC,IAAK,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;QAA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AAI,EAAE,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "light-async-queue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready Redis-free async job queue for single-node reliability",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/src/index.js",
|
|
11
|
+
"types": "./dist/src/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=19.0.0",
|
|
16
|
+
"pnpm": ">=8.0.0"
|
|
17
|
+
},
|
|
18
|
+
"packageManager": "pnpm@8.15.0",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/src/",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"queue",
|
|
26
|
+
"job",
|
|
27
|
+
"async",
|
|
28
|
+
"worker",
|
|
29
|
+
"task",
|
|
30
|
+
"background",
|
|
31
|
+
"retry",
|
|
32
|
+
"dlq",
|
|
33
|
+
"job-queue",
|
|
34
|
+
"task-queue",
|
|
35
|
+
"background-jobs",
|
|
36
|
+
"redis-free",
|
|
37
|
+
"typescript"
|
|
38
|
+
],
|
|
39
|
+
"author": "Akshay Gaikwad <gaikwad.akshay79@gmail.com>",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/gaikwadakshay79/light-async-queue.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/gaikwadakshay79/light-async-queue/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/gaikwadakshay79/light-async-queue#readme",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@types/node": "^20.10.0",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
54
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
55
|
+
"eslint": "^10.0.0",
|
|
56
|
+
"globals": "^17.3.0",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vitest": "^4.0.18"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc",
|
|
62
|
+
"dev": "tsc --watch",
|
|
63
|
+
"lint": "eslint src test --ext .ts",
|
|
64
|
+
"lint:fix": "eslint src test --ext .ts --fix",
|
|
65
|
+
"example": "pnpm run build && node dist/example/basic.js",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"test:watch": "vitest",
|
|
68
|
+
"test:coverage": "vitest run --coverage",
|
|
69
|
+
"clean": "rm -rf dist"
|
|
70
|
+
}
|
|
71
|
+
}
|