fix(bull): requeue jobs after restart
This commit is contained in:
+16
-11
@@ -117,15 +117,24 @@ if (cluster.isMaster) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post(`/admin/${process.env.BULL_AUTH_KEY}/shutdown`, async (req, res) => {
|
app.post(`/admin/${process.env.BULL_AUTH_KEY}/shutdown`, async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log("Gracefully shutting down...");
|
||||||
|
await getWebScraperQueue().pause(false, true);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post(`/admin/${process.env.BULL_AUTH_KEY}/unpause`, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const wsq = getWebScraperQueue();
|
const wsq = getWebScraperQueue();
|
||||||
|
|
||||||
console.log("Gracefully shutting down...");
|
|
||||||
|
|
||||||
await wsq.pause(false, true);
|
|
||||||
|
|
||||||
const jobs = await wsq.getActive();
|
const jobs = await wsq.getActive();
|
||||||
|
|
||||||
|
console.log("Requeueing", jobs.length, "jobs...");
|
||||||
|
|
||||||
if (jobs.length > 0) {
|
if (jobs.length > 0) {
|
||||||
console.log(" Removing", jobs.length, "jobs...");
|
console.log(" Removing", jobs.length, "jobs...");
|
||||||
|
|
||||||
@@ -145,20 +154,16 @@ if (cluster.isMaster) {
|
|||||||
})));
|
})));
|
||||||
|
|
||||||
console.log(" Done!");
|
console.log(" Done!");
|
||||||
|
|
||||||
res.json({ ok: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await getWebScraperQueue().resume(false);
|
||||||
|
res.json({ ok: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return res.status(500).json({ error: error.message });
|
return res.status(500).json({ error: error.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post(`/admin/${process.env.BULL_AUTH_KEY}/unpause`, async (req, res) => {
|
|
||||||
await getWebScraperQueue().resume(false);
|
|
||||||
res.json({ ok: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get(`/serverHealthCheck`, async (req, res) => {
|
app.get(`/serverHealthCheck`, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const webScraperQueue = getWebScraperQueue();
|
const webScraperQueue = getWebScraperQueue();
|
||||||
|
|||||||
Reference in New Issue
Block a user