Improve queue management error handling

This commit is contained in:
Dominic Ferrando
2026-07-12 01:56:56 -04:00
parent 8b81156f6c
commit 4d1b3bc3ef
2 changed files with 12 additions and 5 deletions
+7 -2
View File
@@ -321,11 +321,16 @@ app.listen(3000, async () => {
for (const queue of queues) { for (const queue of queues) {
(async () => { (async () => {
while (true) { while (true) {
try {
// clean, if ready // clean, if ready
if ((Date.now() - queue.lastCleanDate.getTime()) >= queue.cfg.concurrency.timeoutMs) if ((Date.now() - queue.lastCleanDate.getTime()) >= queue.cfg.concurrency.timeoutMs)
await queue.clean().catch((err) => log.error(err)); await queue.clean().catch((err) => log.error({ name: queue.type, err }));
// drain // drain
await queue.drain().catch((err) => log.error(err)); await queue.drain();
}
catch (err) {
log.error({ name: queue.type, err }, "error occurred during queue management");
}
await sleep(EVENT_QUEUE_MANAGE_DELAY_MS); await sleep(EVENT_QUEUE_MANAGE_DELAY_MS);
} }
})(); })();
+2
View File
@@ -38,9 +38,11 @@ type EventQueueServiceOptions<Payload extends JsonValue, State extends JsonValue
export class EventQueueService<Payload extends JsonValue, State extends JsonValue> { export class EventQueueService<Payload extends JsonValue, State extends JsonValue> {
private _lastCleanDate: Date = new Date(0); private _lastCleanDate: Date = new Date(0);
readonly cfg: EventQueueServiceOptions<Payload, State>["cfg"]; readonly cfg: EventQueueServiceOptions<Payload, State>["cfg"];
readonly type: EventType
constructor(private readonly opt: EventQueueServiceOptions<Payload, State>) { constructor(private readonly opt: EventQueueServiceOptions<Payload, State>) {
this.cfg = opt.cfg; this.cfg = opt.cfg;
this.type = opt.type;
} }
get lastCleanDate() { return this._lastCleanDate; }; get lastCleanDate() { return this._lastCleanDate; };