Attempt to stop active jobs
This commit is contained in:
1 parent
0f30d58125
commit
120296763b
1 file changed
+26
-9
@@ -36,10 +36,10 @@ class JobQueue {
|
|||||||
host: redisHost,
|
host: redisHost,
|
||||||
port: redisPort,
|
port: redisPort,
|
||||||
};
|
};
|
||||||
this.connection = connection;
|
|
||||||
this.queue = new Queue(QUEUE_NAME, {
|
this.queue = new Queue(QUEUE_NAME, {
|
||||||
connection,
|
connection,
|
||||||
});
|
});
|
||||||
|
this.connection = connection;
|
||||||
this.workers = [];
|
this.workers = [];
|
||||||
this.db = null;
|
this.db = null;
|
||||||
this.networkService = null;
|
this.networkService = null;
|
||||||
@@ -406,9 +406,6 @@ class JobQueue {
|
|||||||
delayed: await this.queue.getDelayedCount(),
|
delayed: await this.queue.getDelayedCount(),
|
||||||
repeatableJobs: (await this.queue.getRepeatableJobs()).length,
|
repeatableJobs: (await this.queue.getRepeatableJobs()).length,
|
||||||
};
|
};
|
||||||
this.logger.info({
|
|
||||||
message: metrics,
|
|
||||||
});
|
|
||||||
return metrics;
|
return metrics;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
@@ -424,17 +421,33 @@ class JobQueue {
|
|||||||
* @async
|
* @async
|
||||||
* @returns {Promise<boolean>} - Returns true if obliteration is successful
|
* @returns {Promise<boolean>} - Returns true if obliteration is successful
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async obliterate() {
|
async obliterate() {
|
||||||
try {
|
try {
|
||||||
let metrics = await this.getMetrics();
|
this.logger.info({ message: "Attempting to obliterate job queue..." });
|
||||||
this.logger.info({ message: metrics });
|
|
||||||
await this.queue.pause();
|
await this.queue.pause();
|
||||||
const jobs = await this.getJobs();
|
const jobs = await this.getJobs();
|
||||||
|
|
||||||
|
// Stop currently active jobs
|
||||||
|
const redisClient = await this.queue.client;
|
||||||
|
const activeJobs = await this.queue.getJobs(["active"]);
|
||||||
|
if (activeJobs.length !== 0) {
|
||||||
|
this.logger.info({ message: "Attempting to stop active jobs..." });
|
||||||
|
}
|
||||||
|
await Promise.all(
|
||||||
|
activeJobs.map(async (job) => {
|
||||||
|
await redisClient.del(`${this.queue.toKey(job.id)}:lock`);
|
||||||
|
await job.remove();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove all repeatable jobs
|
||||||
for (const job of jobs) {
|
for (const job of jobs) {
|
||||||
await this.queue.removeRepeatableByKey(job.key);
|
await this.queue.removeRepeatableByKey(job.key);
|
||||||
await this.queue.remove(job.id);
|
await this.queue.remove(job.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close workers
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
this.workers.map(async (worker) => {
|
this.workers.map(async (worker) => {
|
||||||
await worker.close();
|
await worker.close();
|
||||||
@@ -442,9 +455,13 @@ class JobQueue {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this.queue.obliterate();
|
await this.queue.obliterate();
|
||||||
metrics = await this.getMetrics();
|
const metrics = await this.getMetrics();
|
||||||
this.logger.info({ message: metrics });
|
this.logger.info({
|
||||||
this.logger.info({ message: successMessages.JOB_QUEUE_OBLITERATE });
|
message: successMessages.JOB_QUEUE_OBLITERATE,
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "obliterate",
|
||||||
|
details: metrics,
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||||
|
|||||||
Reference in new issue
Block a user