bunqueue 1.9.1 → 1.9.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/dist/application/operations/queueControl.d.ts.map +1 -1
- package/dist/application/operations/queueControl.js +6 -1
- package/dist/application/operations/queueControl.js.map +1 -1
- package/dist/application/queueManager.d.ts +115 -9
- package/dist/application/queueManager.d.ts.map +1 -1
- package/dist/application/queueManager.js +535 -26
- package/dist/application/queueManager.js.map +1 -1
- package/dist/cli/client.d.ts +6 -0
- package/dist/cli/client.d.ts.map +1 -1
- package/dist/cli/client.js +60 -48
- package/dist/cli/client.js.map +1 -1
- package/dist/cli/commands/server.d.ts.map +1 -1
- package/dist/cli/commands/server.js +30 -14
- package/dist/cli/commands/server.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +10 -6
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +15 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/client/queue/dlqOps.d.ts +24 -0
- package/dist/client/queue/dlqOps.d.ts.map +1 -0
- package/dist/client/queue/dlqOps.js +73 -0
- package/dist/client/queue/dlqOps.js.map +1 -0
- package/dist/client/queue/helpers.d.ts +20 -0
- package/dist/client/queue/helpers.d.ts.map +1 -0
- package/dist/client/queue/helpers.js +34 -0
- package/dist/client/queue/helpers.js.map +1 -0
- package/dist/client/queue/index.d.ts +8 -0
- package/dist/client/queue/index.d.ts.map +1 -0
- package/dist/client/queue/index.js +8 -0
- package/dist/client/queue/index.js.map +1 -0
- package/dist/client/queue/queue.d.ts +60 -0
- package/dist/client/queue/queue.d.ts.map +1 -0
- package/dist/client/queue/queue.js +322 -0
- package/dist/client/queue/queue.js.map +1 -0
- package/dist/client/queue.d.ts +3 -78
- package/dist/client/queue.d.ts.map +1 -1
- package/dist/client/queue.js +3 -463
- package/dist/client/queue.js.map +1 -1
- package/dist/client/sandboxed/index.d.ts +8 -0
- package/dist/client/sandboxed/index.d.ts.map +1 -0
- package/dist/client/sandboxed/index.js +7 -0
- package/dist/client/sandboxed/index.js.map +1 -0
- package/dist/client/sandboxed/types.d.ts +62 -0
- package/dist/client/sandboxed/types.d.ts.map +1 -0
- package/dist/client/sandboxed/types.js +6 -0
- package/dist/client/sandboxed/types.js.map +1 -0
- package/dist/client/sandboxed/worker.d.ts +38 -0
- package/dist/client/sandboxed/worker.d.ts.map +1 -0
- package/dist/client/sandboxed/worker.js +176 -0
- package/dist/client/sandboxed/worker.js.map +1 -0
- package/dist/client/sandboxed/wrapper.d.ts +13 -0
- package/dist/client/sandboxed/wrapper.d.ts.map +1 -0
- package/dist/client/sandboxed/wrapper.js +65 -0
- package/dist/client/sandboxed/wrapper.js.map +1 -0
- package/dist/client/sandboxedWorker.d.ts +4 -87
- package/dist/client/sandboxedWorker.d.ts.map +1 -1
- package/dist/client/sandboxedWorker.js +3 -296
- package/dist/client/sandboxedWorker.js.map +1 -1
- package/dist/client/tcp/client.d.ts +40 -0
- package/dist/client/tcp/client.d.ts.map +1 -0
- package/dist/client/tcp/client.js +289 -0
- package/dist/client/tcp/client.js.map +1 -0
- package/dist/client/tcp/connection.d.ts +57 -0
- package/dist/client/tcp/connection.d.ts.map +1 -0
- package/dist/client/tcp/connection.js +162 -0
- package/dist/client/tcp/connection.js.map +1 -0
- package/dist/client/tcp/health.d.ts +47 -0
- package/dist/client/tcp/health.d.ts.map +1 -0
- package/dist/client/tcp/health.js +95 -0
- package/dist/client/tcp/health.js.map +1 -0
- package/dist/client/tcp/index.d.ts +13 -0
- package/dist/client/tcp/index.d.ts.map +1 -0
- package/dist/client/tcp/index.js +12 -0
- package/dist/client/tcp/index.js.map +1 -0
- package/dist/client/tcp/lineBuffer.d.ts +17 -0
- package/dist/client/tcp/lineBuffer.d.ts.map +1 -0
- package/dist/client/tcp/lineBuffer.js +32 -0
- package/dist/client/tcp/lineBuffer.js.map +1 -0
- package/dist/client/tcp/reconnect.d.ts +38 -0
- package/dist/client/tcp/reconnect.d.ts.map +1 -0
- package/dist/client/tcp/reconnect.js +70 -0
- package/dist/client/tcp/reconnect.js.map +1 -0
- package/dist/client/tcp/shared.d.ts +11 -0
- package/dist/client/tcp/shared.d.ts.map +1 -0
- package/dist/client/tcp/shared.js +20 -0
- package/dist/client/tcp/shared.js.map +1 -0
- package/dist/client/tcp/types.d.ts +76 -0
- package/dist/client/tcp/types.d.ts.map +1 -0
- package/dist/client/tcp/types.js +20 -0
- package/dist/client/tcp/types.js.map +1 -0
- package/dist/client/tcpClient.d.ts +4 -110
- package/dist/client/tcpClient.d.ts.map +1 -1
- package/dist/client/tcpClient.js +3 -523
- package/dist/client/tcpClient.js.map +1 -1
- package/dist/client/tcpPool.d.ts +3 -0
- package/dist/client/tcpPool.d.ts.map +1 -1
- package/dist/client/tcpPool.js +21 -2
- package/dist/client/tcpPool.js.map +1 -1
- package/dist/client/types.d.ts +11 -2
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/client/worker/ackBatcher.d.ts +40 -0
- package/dist/client/worker/ackBatcher.d.ts.map +1 -0
- package/dist/client/worker/ackBatcher.js +137 -0
- package/dist/client/worker/ackBatcher.js.map +1 -0
- package/dist/client/worker/index.d.ts +11 -0
- package/dist/client/worker/index.d.ts.map +1 -0
- package/dist/client/worker/index.js +10 -0
- package/dist/client/worker/index.js.map +1 -0
- package/dist/client/worker/jobParser.d.ts +10 -0
- package/dist/client/worker/jobParser.d.ts.map +1 -0
- package/dist/client/worker/jobParser.js +43 -0
- package/dist/client/worker/jobParser.js.map +1 -0
- package/dist/client/worker/processor.d.ts +24 -0
- package/dist/client/worker/processor.d.ts.map +1 -0
- package/dist/client/worker/processor.js +86 -0
- package/dist/client/worker/processor.js.map +1 -0
- package/dist/client/worker/types.d.ts +38 -0
- package/dist/client/worker/types.d.ts.map +1 -0
- package/dist/client/worker/types.js +14 -0
- package/dist/client/worker/types.js.map +1 -0
- package/dist/client/worker/worker.d.ts +53 -0
- package/dist/client/worker/worker.d.ts.map +1 -0
- package/dist/client/worker/worker.js +367 -0
- package/dist/client/worker/worker.js.map +1 -0
- package/dist/client/worker.d.ts +3 -69
- package/dist/client/worker.d.ts.map +1 -1
- package/dist/client/worker.js +3 -472
- package/dist/client/worker.js.map +1 -1
- package/dist/domain/queue/shard.d.ts +19 -2
- package/dist/domain/queue/shard.d.ts.map +1 -1
- package/dist/domain/queue/shard.js +36 -4
- package/dist/domain/queue/shard.js.map +1 -1
- package/dist/domain/types/command.d.ts +9 -0
- package/dist/domain/types/command.d.ts.map +1 -1
- package/dist/domain/types/job.d.ts +27 -0
- package/dist/domain/types/job.d.ts.map +1 -1
- package/dist/domain/types/job.js +34 -0
- package/dist/domain/types/job.js.map +1 -1
- package/dist/domain/types/response.d.ts +15 -1
- package/dist/domain/types/response.d.ts.map +1 -1
- package/dist/domain/types/response.js +16 -0
- package/dist/domain/types/response.js.map +1 -1
- package/dist/infrastructure/server/handlers/core.d.ts +1 -1
- package/dist/infrastructure/server/handlers/core.d.ts.map +1 -1
- package/dist/infrastructure/server/handlers/core.js +74 -15
- package/dist/infrastructure/server/handlers/core.js.map +1 -1
- package/dist/infrastructure/server/handlers/monitoring.d.ts.map +1 -1
- package/dist/infrastructure/server/handlers/monitoring.js +6 -4
- package/dist/infrastructure/server/handlers/monitoring.js.map +1 -1
- package/dist/infrastructure/server/http.d.ts +10 -3
- package/dist/infrastructure/server/http.d.ts.map +1 -1
- package/dist/infrastructure/server/http.js +244 -163
- package/dist/infrastructure/server/http.js.map +1 -1
- package/dist/infrastructure/server/tcp.d.ts +8 -3
- package/dist/infrastructure/server/tcp.d.ts.map +1 -1
- package/dist/infrastructure/server/tcp.js +77 -57
- package/dist/infrastructure/server/tcp.js.map +1 -1
- package/dist/infrastructure/server/types.d.ts +2 -0
- package/dist/infrastructure/server/types.d.ts.map +1 -1
- package/dist/main.js +24 -4
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,299 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* SandboxedWorker - Re-exports from sandboxed module
|
|
3
|
+
* @deprecated Import from './sandboxed' instead
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import { writeFileSync, unlinkSync, existsSync, mkdirSync } from 'fs';
|
|
8
|
-
import { tmpdir } from 'os';
|
|
9
|
-
/**
|
|
10
|
-
* Sandboxed Worker - runs processors in isolated Bun Worker processes
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { Queue, SandboxedWorker } from 'bunqueue/client';
|
|
15
|
-
*
|
|
16
|
-
* const queue = new Queue('cpu-intensive');
|
|
17
|
-
*
|
|
18
|
-
* // Create processor file: processor.ts
|
|
19
|
-
* // export default async (job) => {
|
|
20
|
-
* // const result = heavyComputation(job.data);
|
|
21
|
-
* // return result;
|
|
22
|
-
* // };
|
|
23
|
-
*
|
|
24
|
-
* const worker = new SandboxedWorker('cpu-intensive', {
|
|
25
|
-
* processor: './processor.ts',
|
|
26
|
-
* concurrency: 4,
|
|
27
|
-
* timeout: 60000,
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* await worker.start();
|
|
31
|
-
* // Workers process jobs in isolated processes
|
|
32
|
-
* // If one crashes, others continue working
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export class SandboxedWorker {
|
|
36
|
-
queueName;
|
|
37
|
-
options;
|
|
38
|
-
workers = [];
|
|
39
|
-
running = false;
|
|
40
|
-
pullPromise = null;
|
|
41
|
-
wrapperPath = null;
|
|
42
|
-
manager;
|
|
43
|
-
constructor(queueName, options) {
|
|
44
|
-
this.queueName = queueName;
|
|
45
|
-
this.manager = options.manager ?? getSharedManager();
|
|
46
|
-
this.options = {
|
|
47
|
-
processor: options.processor,
|
|
48
|
-
concurrency: options.concurrency ?? 1,
|
|
49
|
-
maxMemory: options.maxMemory ?? 256,
|
|
50
|
-
timeout: options.timeout ?? 30000,
|
|
51
|
-
autoRestart: options.autoRestart ?? true,
|
|
52
|
-
maxRestarts: options.maxRestarts ?? 10,
|
|
53
|
-
pollInterval: options.pollInterval ?? 10,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
/** Start the sandboxed worker pool */
|
|
57
|
-
start() {
|
|
58
|
-
if (this.running)
|
|
59
|
-
return;
|
|
60
|
-
this.running = true;
|
|
61
|
-
// Create wrapper script for workers
|
|
62
|
-
this.wrapperPath = this.createWrapperScript();
|
|
63
|
-
// Spawn worker processes
|
|
64
|
-
for (let i = 0; i < this.options.concurrency; i++) {
|
|
65
|
-
this.spawnWorker(i);
|
|
66
|
-
}
|
|
67
|
-
// Start pulling jobs
|
|
68
|
-
this.pullPromise = this.pullLoop();
|
|
69
|
-
}
|
|
70
|
-
/** Stop all workers gracefully */
|
|
71
|
-
async stop() {
|
|
72
|
-
this.running = false;
|
|
73
|
-
// Clear all timeouts
|
|
74
|
-
for (const wp of this.workers) {
|
|
75
|
-
if (wp.timeoutId) {
|
|
76
|
-
clearTimeout(wp.timeoutId);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Terminate all workers
|
|
80
|
-
for (const wp of this.workers) {
|
|
81
|
-
wp.worker.terminate();
|
|
82
|
-
}
|
|
83
|
-
this.workers.length = 0;
|
|
84
|
-
// Wait for pull loop to finish
|
|
85
|
-
if (this.pullPromise) {
|
|
86
|
-
await this.pullPromise;
|
|
87
|
-
}
|
|
88
|
-
// Cleanup wrapper script
|
|
89
|
-
if (this.wrapperPath && existsSync(this.wrapperPath)) {
|
|
90
|
-
try {
|
|
91
|
-
unlinkSync(this.wrapperPath);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
// Ignore cleanup errors
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/** Get worker pool stats */
|
|
99
|
-
getStats() {
|
|
100
|
-
const busy = this.workers.filter((w) => w.busy).length;
|
|
101
|
-
const restarts = this.workers.reduce((sum, w) => sum + w.restarts, 0);
|
|
102
|
-
return {
|
|
103
|
-
total: this.workers.length,
|
|
104
|
-
busy,
|
|
105
|
-
idle: this.workers.length - busy,
|
|
106
|
-
restarts,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/** Create wrapper script file that loads the processor */
|
|
110
|
-
createWrapperScript() {
|
|
111
|
-
const processorPath = this.options.processor.startsWith('/')
|
|
112
|
-
? this.options.processor
|
|
113
|
-
: join(process.cwd(), this.options.processor);
|
|
114
|
-
const wrapperCode = `
|
|
115
|
-
// Sandboxed Worker Wrapper
|
|
116
|
-
const processor = (await import('${processorPath}')).default;
|
|
117
|
-
|
|
118
|
-
self.onmessage = async (event) => {
|
|
119
|
-
const { type, job } = event.data;
|
|
120
|
-
if (type !== 'job') return;
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const result = await processor({
|
|
124
|
-
id: job.id,
|
|
125
|
-
data: job.data,
|
|
126
|
-
queue: job.queue,
|
|
127
|
-
attempts: job.attempts,
|
|
128
|
-
progress: (value) => {
|
|
129
|
-
self.postMessage({ type: 'progress', jobId: job.id, progress: value });
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
self.postMessage({ type: 'result', jobId: job.id, result });
|
|
134
|
-
} catch (err) {
|
|
135
|
-
self.postMessage({
|
|
136
|
-
type: 'error',
|
|
137
|
-
jobId: job.id,
|
|
138
|
-
error: err instanceof Error ? err.message : String(err),
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
`;
|
|
143
|
-
// Write to temp file
|
|
144
|
-
const tempDir = join(tmpdir(), 'bunqueue-workers');
|
|
145
|
-
if (!existsSync(tempDir)) {
|
|
146
|
-
mkdirSync(tempDir, { recursive: true });
|
|
147
|
-
}
|
|
148
|
-
const wrapperPath = join(tempDir, `worker-${this.queueName}-${Date.now()}.ts`);
|
|
149
|
-
writeFileSync(wrapperPath, wrapperCode);
|
|
150
|
-
return wrapperPath;
|
|
151
|
-
}
|
|
152
|
-
/** Spawn a single worker process */
|
|
153
|
-
spawnWorker(index) {
|
|
154
|
-
if (!this.wrapperPath)
|
|
155
|
-
return;
|
|
156
|
-
const worker = new Worker(this.wrapperPath, {
|
|
157
|
-
smol: this.options.maxMemory <= 64,
|
|
158
|
-
});
|
|
159
|
-
const wp = {
|
|
160
|
-
worker,
|
|
161
|
-
busy: false,
|
|
162
|
-
currentJob: null,
|
|
163
|
-
restarts: this.workers[index]?.restarts ?? 0,
|
|
164
|
-
timeoutId: null,
|
|
165
|
-
};
|
|
166
|
-
// Handle messages from worker
|
|
167
|
-
worker.onmessage = (event) => {
|
|
168
|
-
this.handleWorkerMessage(wp, event.data);
|
|
169
|
-
};
|
|
170
|
-
// Handle worker errors/crashes
|
|
171
|
-
worker.onerror = (error) => {
|
|
172
|
-
console.error(`[SandboxedWorker] Worker ${index} error:`, error.message);
|
|
173
|
-
this.handleWorkerCrash(wp, index);
|
|
174
|
-
};
|
|
175
|
-
if (this.workers[index]) {
|
|
176
|
-
this.workers[index] = wp;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.workers.push(wp);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/** Main loop - pull jobs and dispatch to workers */
|
|
183
|
-
async pullLoop() {
|
|
184
|
-
while (this.running) {
|
|
185
|
-
// Find idle worker
|
|
186
|
-
const idleWorker = this.workers.find((w) => !w.busy);
|
|
187
|
-
if (!idleWorker) {
|
|
188
|
-
await Bun.sleep(this.options.pollInterval);
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
// Pull job from queue using manager
|
|
192
|
-
const job = await this.manager.pull(this.queueName, 1000);
|
|
193
|
-
if (!job)
|
|
194
|
-
continue;
|
|
195
|
-
// Dispatch to worker
|
|
196
|
-
this.dispatchJob(idleWorker, job);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/** Dispatch job to a worker process */
|
|
200
|
-
dispatchJob(wp, job) {
|
|
201
|
-
wp.busy = true;
|
|
202
|
-
wp.currentJob = job;
|
|
203
|
-
// Set timeout
|
|
204
|
-
wp.timeoutId = setTimeout(() => {
|
|
205
|
-
this.handleJobTimeout(wp, job);
|
|
206
|
-
}, this.options.timeout);
|
|
207
|
-
// Send job to worker
|
|
208
|
-
const request = {
|
|
209
|
-
type: 'job',
|
|
210
|
-
job: {
|
|
211
|
-
id: String(job.id),
|
|
212
|
-
data: job.data,
|
|
213
|
-
queue: job.queue,
|
|
214
|
-
attempts: job.attempts,
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
wp.worker.postMessage(request);
|
|
218
|
-
}
|
|
219
|
-
/** Handle message from worker */
|
|
220
|
-
handleWorkerMessage(wp, msg) {
|
|
221
|
-
if (!wp.currentJob || msg.jobId !== String(wp.currentJob.id))
|
|
222
|
-
return;
|
|
223
|
-
switch (msg.type) {
|
|
224
|
-
case 'result':
|
|
225
|
-
this.completeJob(wp, msg.result);
|
|
226
|
-
break;
|
|
227
|
-
case 'error':
|
|
228
|
-
this.failJob(wp, msg.error ?? 'Unknown error');
|
|
229
|
-
break;
|
|
230
|
-
case 'progress':
|
|
231
|
-
if (msg.progress !== undefined) {
|
|
232
|
-
this.manager.updateProgress(wp.currentJob.id, msg.progress).catch(() => { });
|
|
233
|
-
}
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/** Complete a job successfully */
|
|
238
|
-
completeJob(wp, result) {
|
|
239
|
-
if (wp.timeoutId) {
|
|
240
|
-
clearTimeout(wp.timeoutId);
|
|
241
|
-
wp.timeoutId = null;
|
|
242
|
-
}
|
|
243
|
-
if (wp.currentJob) {
|
|
244
|
-
const jobId = wp.currentJob.id;
|
|
245
|
-
this.manager.ack(jobId, result).catch((err) => {
|
|
246
|
-
console.error(`[SandboxedWorker] Failed to ack job ${jobId}:`, err);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
wp.busy = false;
|
|
250
|
-
wp.currentJob = null;
|
|
251
|
-
}
|
|
252
|
-
/** Fail a job */
|
|
253
|
-
failJob(wp, error) {
|
|
254
|
-
if (wp.timeoutId) {
|
|
255
|
-
clearTimeout(wp.timeoutId);
|
|
256
|
-
wp.timeoutId = null;
|
|
257
|
-
}
|
|
258
|
-
if (wp.currentJob) {
|
|
259
|
-
const jobId = wp.currentJob.id;
|
|
260
|
-
this.manager.fail(jobId, error).catch((err) => {
|
|
261
|
-
console.error(`[SandboxedWorker] Failed to fail job ${jobId}:`, err);
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
wp.busy = false;
|
|
265
|
-
wp.currentJob = null;
|
|
266
|
-
}
|
|
267
|
-
/** Handle job timeout */
|
|
268
|
-
handleJobTimeout(wp, job) {
|
|
269
|
-
console.error(`[SandboxedWorker] Job ${job.id} timed out after ${this.options.timeout}ms`);
|
|
270
|
-
// Terminate the stuck worker
|
|
271
|
-
wp.worker.terminate();
|
|
272
|
-
// Fail the job
|
|
273
|
-
this.manager.fail(job.id, `Job timed out after ${this.options.timeout}ms`).catch(() => { });
|
|
274
|
-
// Restart worker if allowed
|
|
275
|
-
const index = this.workers.indexOf(wp);
|
|
276
|
-
if (index !== -1) {
|
|
277
|
-
this.handleWorkerCrash(wp, index);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
/** Handle worker crash and potentially restart */
|
|
281
|
-
handleWorkerCrash(wp, index) {
|
|
282
|
-
// Fail current job if any
|
|
283
|
-
if (wp.currentJob) {
|
|
284
|
-
this.manager.fail(wp.currentJob.id, 'Worker crashed').catch(() => { });
|
|
285
|
-
}
|
|
286
|
-
wp.busy = false;
|
|
287
|
-
wp.currentJob = null;
|
|
288
|
-
wp.restarts++;
|
|
289
|
-
// Check if we should restart
|
|
290
|
-
if (this.options.autoRestart && wp.restarts < this.options.maxRestarts && this.running) {
|
|
291
|
-
console.log(`[SandboxedWorker] Restarting worker ${index} (attempt ${wp.restarts})`);
|
|
292
|
-
this.spawnWorker(index);
|
|
293
|
-
}
|
|
294
|
-
else if (wp.restarts >= this.options.maxRestarts) {
|
|
295
|
-
console.error(`[SandboxedWorker] Worker ${index} exceeded max restarts (${this.options.maxRestarts})`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
5
|
+
export { SandboxedWorker } from './sandboxed';
|
|
299
6
|
//# sourceMappingURL=sandboxedWorker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxedWorker.js","sourceRoot":"","sources":["../../src/client/sandboxedWorker.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"sandboxedWorker.js","sourceRoot":"","sources":["../../src/client/sandboxedWorker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client
|
|
3
|
+
* Production-ready TCP client with auto-reconnection
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import type { ConnectionOptions, ConnectionHealth } from './types';
|
|
7
|
+
export declare class TcpClient extends EventEmitter {
|
|
8
|
+
private socket;
|
|
9
|
+
private connected;
|
|
10
|
+
private connecting;
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly health;
|
|
13
|
+
private readonly reconnect;
|
|
14
|
+
private readonly commands;
|
|
15
|
+
constructor(options?: Partial<ConnectionOptions>);
|
|
16
|
+
/** Connect to server */
|
|
17
|
+
connect(): Promise<void>;
|
|
18
|
+
private waitForConnection;
|
|
19
|
+
private doConnect;
|
|
20
|
+
private authenticate;
|
|
21
|
+
private handleData;
|
|
22
|
+
private handleClose;
|
|
23
|
+
/** Send ping to check connection health */
|
|
24
|
+
ping(): Promise<boolean>;
|
|
25
|
+
private handlePingFailure;
|
|
26
|
+
private forceReconnect;
|
|
27
|
+
/** Get connection health metrics */
|
|
28
|
+
getHealth(): ConnectionHealth;
|
|
29
|
+
private sendInternal;
|
|
30
|
+
private processNextCommand;
|
|
31
|
+
/** Send command and wait for response */
|
|
32
|
+
send(command: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
33
|
+
/** Close connection */
|
|
34
|
+
close(): void;
|
|
35
|
+
/** Check if connected */
|
|
36
|
+
isConnected(): boolean;
|
|
37
|
+
/** Get connection state */
|
|
38
|
+
getState(): 'connected' | 'connecting' | 'disconnected' | 'closed';
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAiB,MAAM,SAAS,CAAC;AAclF,qBAAa,SAAU,SAAQ,YAAY;IACzC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAsBpD,wBAAwB;IAClB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B9B,OAAO,CAAC,iBAAiB;YAeX,SAAS;YA6BT,YAAY;IAO1B,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,WAAW;IAiBnB,2CAA2C;IACrC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAoB9B,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,cAAc;IAWtB,oCAAoC;IACpC,SAAS,IAAI,gBAAgB;YAIf,YAAY;IAmC1B,OAAO,CAAC,kBAAkB;IAU1B,yCAAyC;IACnC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAwC9E,uBAAuB;IACvB,KAAK,IAAI,IAAI;IAYb,yBAAyB;IACzB,WAAW,IAAI,OAAO;IAItB,2BAA2B;IAC3B,QAAQ,IAAI,WAAW,GAAG,YAAY,GAAG,cAAc,GAAG,QAAQ;CAMnE"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client
|
|
3
|
+
* Production-ready TCP client with auto-reconnection
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { DEFAULT_CONNECTION } from './types';
|
|
7
|
+
import { HealthTracker } from './health';
|
|
8
|
+
import { ReconnectManager } from './reconnect';
|
|
9
|
+
import { createConnection, CommandQueue } from './connection';
|
|
10
|
+
export class TcpClient extends EventEmitter {
|
|
11
|
+
socket = null;
|
|
12
|
+
connected = false;
|
|
13
|
+
connecting = false;
|
|
14
|
+
options;
|
|
15
|
+
health;
|
|
16
|
+
reconnect;
|
|
17
|
+
commands;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.options = { ...DEFAULT_CONNECTION, ...options };
|
|
21
|
+
this.commands = new CommandQueue();
|
|
22
|
+
this.health = new HealthTracker({
|
|
23
|
+
pingInterval: this.options.pingInterval,
|
|
24
|
+
maxPingFailures: this.options.maxPingFailures,
|
|
25
|
+
});
|
|
26
|
+
this.reconnect = new ReconnectManager({
|
|
27
|
+
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
28
|
+
reconnectDelay: this.options.reconnectDelay,
|
|
29
|
+
maxReconnectDelay: this.options.maxReconnectDelay,
|
|
30
|
+
autoReconnect: this.options.autoReconnect,
|
|
31
|
+
});
|
|
32
|
+
this.reconnect.on('reconnecting', (data) => this.emit('reconnecting', data));
|
|
33
|
+
this.reconnect.on('maxReconnectAttemptsReached', () => {
|
|
34
|
+
this.emit('maxReconnectAttemptsReached');
|
|
35
|
+
this.commands.rejectAll(new Error('Max reconnection attempts reached'));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Connect to server */
|
|
39
|
+
async connect() {
|
|
40
|
+
if (this.connected)
|
|
41
|
+
return;
|
|
42
|
+
if (this.connecting) {
|
|
43
|
+
return this.waitForConnection();
|
|
44
|
+
}
|
|
45
|
+
this.connecting = true;
|
|
46
|
+
this.reconnect.setClosed(false);
|
|
47
|
+
try {
|
|
48
|
+
await this.doConnect();
|
|
49
|
+
this.reconnect.reset();
|
|
50
|
+
this.emit('connected');
|
|
51
|
+
this.health.startPing(async () => {
|
|
52
|
+
await this.ping();
|
|
53
|
+
});
|
|
54
|
+
this.processNextCommand();
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
this.connecting = false;
|
|
58
|
+
if (this.reconnect.canReconnect()) {
|
|
59
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
60
|
+
}
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
waitForConnection() {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const onConnect = () => {
|
|
67
|
+
this.off('error', onError);
|
|
68
|
+
resolve();
|
|
69
|
+
};
|
|
70
|
+
const onError = (err) => {
|
|
71
|
+
this.off('connected', onConnect);
|
|
72
|
+
reject(err);
|
|
73
|
+
};
|
|
74
|
+
this.once('connected', onConnect);
|
|
75
|
+
this.once('error', onError);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async doConnect() {
|
|
79
|
+
const { socket } = await createConnection({
|
|
80
|
+
socketPath: this.options.socketPath,
|
|
81
|
+
host: this.options.host,
|
|
82
|
+
port: this.options.port,
|
|
83
|
+
}, this.options.connectTimeout, {
|
|
84
|
+
onData: (line) => {
|
|
85
|
+
this.handleData(line);
|
|
86
|
+
},
|
|
87
|
+
onClose: () => {
|
|
88
|
+
this.handleClose();
|
|
89
|
+
},
|
|
90
|
+
onError: (error) => this.emit('error', error),
|
|
91
|
+
});
|
|
92
|
+
this.socket = socket;
|
|
93
|
+
this.connected = true;
|
|
94
|
+
this.connecting = false;
|
|
95
|
+
this.health.recordConnected();
|
|
96
|
+
if (this.options.token) {
|
|
97
|
+
await this.authenticate();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async authenticate() {
|
|
101
|
+
const response = await this.sendInternal({ cmd: 'Auth', token: this.options.token });
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error('Authentication failed');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
handleData(line) {
|
|
107
|
+
const current = this.commands.getCurrentCommand();
|
|
108
|
+
if (!current)
|
|
109
|
+
return;
|
|
110
|
+
try {
|
|
111
|
+
const response = JSON.parse(line);
|
|
112
|
+
clearTimeout(current.timeout);
|
|
113
|
+
current.resolve(response);
|
|
114
|
+
this.commands.setCurrentCommand(null);
|
|
115
|
+
this.processNextCommand();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
clearTimeout(current.timeout);
|
|
119
|
+
current.reject(new Error('Invalid response from server'));
|
|
120
|
+
this.commands.setCurrentCommand(null);
|
|
121
|
+
this.processNextCommand();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
handleClose() {
|
|
125
|
+
const wasConnected = this.connected;
|
|
126
|
+
this.connected = false;
|
|
127
|
+
this.connecting = false;
|
|
128
|
+
this.socket = null;
|
|
129
|
+
this.health.stopPing();
|
|
130
|
+
// Reject current in-flight command so it doesn't hang forever
|
|
131
|
+
this.commands.clearCurrent(new Error('Connection lost'));
|
|
132
|
+
if (wasConnected) {
|
|
133
|
+
this.emit('disconnected');
|
|
134
|
+
if (this.reconnect.canReconnect()) {
|
|
135
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Send ping to check connection health */
|
|
140
|
+
async ping() {
|
|
141
|
+
if (!this.connected)
|
|
142
|
+
return false;
|
|
143
|
+
try {
|
|
144
|
+
const start = Date.now();
|
|
145
|
+
const response = await this.send({ cmd: 'Ping' });
|
|
146
|
+
const success = response.pong === true;
|
|
147
|
+
if (success) {
|
|
148
|
+
this.health.recordPingSuccess(Date.now() - start);
|
|
149
|
+
this.emit('health', { type: 'ping_success', latency: Date.now() - start });
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.handlePingFailure();
|
|
153
|
+
}
|
|
154
|
+
return success;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
this.handlePingFailure();
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
handlePingFailure() {
|
|
162
|
+
if (this.health.recordPingFailure()) {
|
|
163
|
+
this.emit('health', { type: 'unhealthy', reason: 'max_ping_failures' });
|
|
164
|
+
this.forceReconnect();
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.emit('health', { type: 'ping_failed' });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
forceReconnect() {
|
|
171
|
+
if (this.reconnect.isClosed())
|
|
172
|
+
return;
|
|
173
|
+
if (this.socket) {
|
|
174
|
+
this.socket.end();
|
|
175
|
+
this.socket = null;
|
|
176
|
+
}
|
|
177
|
+
this.connected = false;
|
|
178
|
+
this.health.stopPing();
|
|
179
|
+
if (this.reconnect.canReconnect())
|
|
180
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
181
|
+
}
|
|
182
|
+
/** Get connection health metrics */
|
|
183
|
+
getHealth() {
|
|
184
|
+
return this.health.getHealth(this.getState());
|
|
185
|
+
}
|
|
186
|
+
async sendInternal(command) {
|
|
187
|
+
if (!this.socket)
|
|
188
|
+
throw new Error('Not connected');
|
|
189
|
+
const startTime = Date.now();
|
|
190
|
+
this.health.recordCommandSent();
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
const timeout = setTimeout(() => {
|
|
193
|
+
const current = this.commands.getCurrentCommand();
|
|
194
|
+
if (current?.command === command) {
|
|
195
|
+
this.commands.setCurrentCommand(null);
|
|
196
|
+
this.health.recordError();
|
|
197
|
+
reject(new Error('Command timeout'));
|
|
198
|
+
this.processNextCommand();
|
|
199
|
+
}
|
|
200
|
+
}, this.options.commandTimeout);
|
|
201
|
+
this.commands.setCurrentCommand({
|
|
202
|
+
id: 0,
|
|
203
|
+
command,
|
|
204
|
+
resolve: (result) => {
|
|
205
|
+
this.health.recordSuccess(Date.now() - startTime);
|
|
206
|
+
resolve(result);
|
|
207
|
+
},
|
|
208
|
+
reject: (err) => {
|
|
209
|
+
this.health.recordError();
|
|
210
|
+
reject(err);
|
|
211
|
+
},
|
|
212
|
+
timeout,
|
|
213
|
+
});
|
|
214
|
+
this.socket?.write(JSON.stringify(command) + '\n');
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
processNextCommand() {
|
|
218
|
+
if (this.commands.getCurrentCommand() || !this.connected)
|
|
219
|
+
return;
|
|
220
|
+
const next = this.commands.dequeue();
|
|
221
|
+
if (!next || !this.socket)
|
|
222
|
+
return;
|
|
223
|
+
this.commands.setCurrentCommand(next);
|
|
224
|
+
this.socket.write(JSON.stringify(next.command) + '\n');
|
|
225
|
+
}
|
|
226
|
+
/** Send command and wait for response */
|
|
227
|
+
async send(command) {
|
|
228
|
+
if (this.connected && !this.commands.hasPending() && !this.commands.getCurrentCommand()) {
|
|
229
|
+
return this.sendInternal(command);
|
|
230
|
+
}
|
|
231
|
+
const startTime = Date.now();
|
|
232
|
+
this.health.recordCommandSent();
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
const id = this.commands.nextId();
|
|
235
|
+
const timeout = setTimeout(() => {
|
|
236
|
+
if (this.commands.remove(id)) {
|
|
237
|
+
this.health.recordError();
|
|
238
|
+
reject(new Error('Command timeout'));
|
|
239
|
+
}
|
|
240
|
+
}, this.options.commandTimeout);
|
|
241
|
+
this.commands.enqueue({
|
|
242
|
+
id,
|
|
243
|
+
command,
|
|
244
|
+
resolve: (result) => {
|
|
245
|
+
this.health.recordSuccess(Date.now() - startTime);
|
|
246
|
+
resolve(result);
|
|
247
|
+
},
|
|
248
|
+
reject: (err) => {
|
|
249
|
+
this.health.recordError();
|
|
250
|
+
reject(err);
|
|
251
|
+
},
|
|
252
|
+
timeout,
|
|
253
|
+
});
|
|
254
|
+
if (!this.connected && !this.connecting) {
|
|
255
|
+
this.connect().catch(() => { });
|
|
256
|
+
}
|
|
257
|
+
else if (this.connected) {
|
|
258
|
+
this.processNextCommand();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** Close connection */
|
|
263
|
+
close() {
|
|
264
|
+
this.reconnect.setClosed(true);
|
|
265
|
+
this.health.stopPing();
|
|
266
|
+
this.reconnect.cancelReconnect();
|
|
267
|
+
this.commands.rejectAll(new Error('Client closed'));
|
|
268
|
+
if (this.socket) {
|
|
269
|
+
this.socket.end();
|
|
270
|
+
this.socket = null;
|
|
271
|
+
this.connected = false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** Check if connected */
|
|
275
|
+
isConnected() {
|
|
276
|
+
return this.connected;
|
|
277
|
+
}
|
|
278
|
+
/** Get connection state */
|
|
279
|
+
getState() {
|
|
280
|
+
if (this.reconnect.isClosed())
|
|
281
|
+
return 'closed';
|
|
282
|
+
if (this.connected)
|
|
283
|
+
return 'connected';
|
|
284
|
+
if (this.connecting)
|
|
285
|
+
return 'connecting';
|
|
286
|
+
return 'disconnected';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":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