add factory method, better logging
This commit is contained in:
1 parent
e6a387b8b2
commit
3ff0f6d399
1 file changed
+13
-4
@@ -22,7 +22,12 @@ class JobQueue {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.queues = {};
|
this.queues = {};
|
||||||
this.workers = [];
|
this.workers = [];
|
||||||
this.init();
|
}
|
||||||
|
|
||||||
|
static async create({ db, jobQueueHelper, logger, stringService }) {
|
||||||
|
const instance = new JobQueue({ db, jobQueueHelper, logger, stringService });
|
||||||
|
await instance.init();
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
@@ -52,9 +57,13 @@ class JobQueue {
|
|||||||
const queueHealthChecks = await this.checkQueueHealth();
|
const queueHealthChecks = await this.checkQueueHealth();
|
||||||
const queueIsStuck = queueHealthChecks.some((healthCheck) => healthCheck.stuck);
|
const queueIsStuck = queueHealthChecks.some((healthCheck) => healthCheck.stuck);
|
||||||
if (queueIsStuck) {
|
if (queueIsStuck) {
|
||||||
console.log("Queue is stuck");
|
this.logger.warn({
|
||||||
console.log(queueHealthChecks);
|
message: "Queue is stuck",
|
||||||
// await this.flushQueues();
|
service: SERVICE_NAME,
|
||||||
|
method: "periodicHealthCheck",
|
||||||
|
details: queueHealthChecks,
|
||||||
|
});
|
||||||
|
await this.flushQueues();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
|
|||||||
Reference in new issue
Block a user