Improve queue management error handling
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -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; };
|
||||||
|
|||||||
Reference in New Issue
Block a user