@radaros/queue 0.3.10 → 0.3.12
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/index.d.ts +15 -3
- package/dist/index.js +31 -10
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,10 @@ interface QueueConfig {
|
|
|
29
29
|
connection: {
|
|
30
30
|
host: string;
|
|
31
31
|
port: number;
|
|
32
|
-
|
|
32
|
+
password?: string;
|
|
33
|
+
db?: number;
|
|
34
|
+
tls?: boolean;
|
|
35
|
+
} | string;
|
|
33
36
|
queueName?: string;
|
|
34
37
|
defaultJobOptions?: Record<string, unknown>;
|
|
35
38
|
}
|
|
@@ -46,6 +49,10 @@ declare class AgentQueue {
|
|
|
46
49
|
priority?: number;
|
|
47
50
|
delay?: number;
|
|
48
51
|
attempts?: number;
|
|
52
|
+
backoff?: {
|
|
53
|
+
type: "exponential" | "fixed";
|
|
54
|
+
delay: number;
|
|
55
|
+
};
|
|
49
56
|
repeat?: {
|
|
50
57
|
pattern: string;
|
|
51
58
|
};
|
|
@@ -71,9 +78,14 @@ interface WorkerConfig {
|
|
|
71
78
|
connection: {
|
|
72
79
|
host: string;
|
|
73
80
|
port: number;
|
|
74
|
-
|
|
81
|
+
password?: string;
|
|
82
|
+
db?: number;
|
|
83
|
+
tls?: boolean;
|
|
84
|
+
} | string;
|
|
75
85
|
queueName?: string;
|
|
76
86
|
concurrency?: number;
|
|
87
|
+
attempts?: number;
|
|
88
|
+
backoffDelay?: number;
|
|
77
89
|
agentRegistry: Record<string, Agent>;
|
|
78
90
|
workflowRegistry?: Record<string, Workflow<any>>;
|
|
79
91
|
}
|
|
@@ -81,7 +93,7 @@ declare class AgentWorker {
|
|
|
81
93
|
private worker;
|
|
82
94
|
constructor(config: WorkerConfig);
|
|
83
95
|
start(): void;
|
|
84
|
-
stop(): Promise<void>;
|
|
96
|
+
stop(timeoutMs?: number): Promise<void>;
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
declare function bridgeEventBusToJob(eventBus: EventBus, job: any, runId: string): () => void;
|
package/dist/index.js
CHANGED
|
@@ -12,17 +12,21 @@ var AgentQueue = class {
|
|
|
12
12
|
queueName;
|
|
13
13
|
constructor(config) {
|
|
14
14
|
this.queueName = config.queueName ?? "radaros:jobs";
|
|
15
|
+
const connection = typeof config.connection === "string" ? { url: config.connection } : config.connection;
|
|
15
16
|
try {
|
|
16
17
|
const { Queue, QueueEvents } = __require("bullmq");
|
|
17
18
|
this.queue = new Queue(this.queueName, {
|
|
18
|
-
connection
|
|
19
|
+
connection,
|
|
19
20
|
defaultJobOptions: config.defaultJobOptions
|
|
20
21
|
});
|
|
21
22
|
this.queueEvents = new QueueEvents(this.queueName, {
|
|
22
|
-
connection
|
|
23
|
+
connection
|
|
23
24
|
});
|
|
24
|
-
} catch {
|
|
25
|
-
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err?.code === "MODULE_NOT_FOUND" || err?.message?.includes("Cannot find module")) {
|
|
27
|
+
throw new Error("bullmq and ioredis are required for AgentQueue. Install them: npm install bullmq ioredis");
|
|
28
|
+
}
|
|
29
|
+
throw err;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
async enqueueAgentRun(opts) {
|
|
@@ -37,6 +41,7 @@ var AgentQueue = class {
|
|
|
37
41
|
if (opts.priority !== void 0) jobOpts.priority = opts.priority;
|
|
38
42
|
if (opts.delay !== void 0) jobOpts.delay = opts.delay;
|
|
39
43
|
if (opts.attempts !== void 0) jobOpts.attempts = opts.attempts;
|
|
44
|
+
if (opts.backoff) jobOpts.backoff = opts.backoff;
|
|
40
45
|
if (opts.repeat) jobOpts.repeat = opts.repeat;
|
|
41
46
|
const job = await this.queue.add(`agent:${opts.agentName}`, payload, jobOpts);
|
|
42
47
|
return { jobId: job.id };
|
|
@@ -98,6 +103,14 @@ var AgentWorker = class {
|
|
|
98
103
|
constructor(config) {
|
|
99
104
|
const queueName = config.queueName ?? "radaros:jobs";
|
|
100
105
|
const concurrency = config.concurrency ?? 5;
|
|
106
|
+
const connection = typeof config.connection === "string" ? { url: config.connection } : config.connection;
|
|
107
|
+
const defaultJobOptions = {
|
|
108
|
+
attempts: config.attempts ?? 3,
|
|
109
|
+
backoff: {
|
|
110
|
+
type: "exponential",
|
|
111
|
+
delay: config.backoffDelay ?? 1e3
|
|
112
|
+
}
|
|
113
|
+
};
|
|
101
114
|
try {
|
|
102
115
|
const { Worker } = __require("bullmq");
|
|
103
116
|
this.worker = new Worker(
|
|
@@ -136,18 +149,26 @@ var AgentWorker = class {
|
|
|
136
149
|
throw new Error(`Unknown job type: ${payload.type}`);
|
|
137
150
|
},
|
|
138
151
|
{
|
|
139
|
-
connection
|
|
140
|
-
concurrency
|
|
152
|
+
connection,
|
|
153
|
+
concurrency,
|
|
154
|
+
defaultJobOptions
|
|
141
155
|
}
|
|
142
156
|
);
|
|
143
|
-
} catch {
|
|
144
|
-
|
|
157
|
+
} catch (err) {
|
|
158
|
+
if (err?.code === "MODULE_NOT_FOUND" || err?.message?.includes("Cannot find module")) {
|
|
159
|
+
throw new Error("bullmq and ioredis are required for AgentWorker. Install them: npm install bullmq ioredis");
|
|
160
|
+
}
|
|
161
|
+
throw err;
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
start() {
|
|
148
165
|
}
|
|
149
|
-
async stop() {
|
|
150
|
-
await
|
|
166
|
+
async stop(timeoutMs = 3e4) {
|
|
167
|
+
await Promise.race([
|
|
168
|
+
this.worker.close(),
|
|
169
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Worker drain timeout")), timeoutMs))
|
|
170
|
+
]).catch(() => {
|
|
171
|
+
});
|
|
151
172
|
}
|
|
152
173
|
};
|
|
153
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radaros/queue",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"typescript": "^5.6.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@radaros/core": "^0.3.
|
|
27
|
+
"@radaros/core": "^0.3.12",
|
|
28
28
|
"bullmq": "^5.0.0",
|
|
29
29
|
"ioredis": "^5.0.0"
|
|
30
30
|
},
|