Stalled jobs aren't removed by removeRepeatable
Created by: Sicria
If a job stalls and the process is restarted, when the process comes back up, they report as being stalled, then attempt to run, if successful they reschedule themselves to run again.
Before scheduling a job to be repeated I call queue.removeRepeatable
to remove any previously set jobs of this same type.
It seems that removeRepeatable
isn't removing jobs which previously stalled?
Here's a wrapper function I created to schedule jobs if the config option is enabled.
export const scheduleTask = ({ queue }, name) => {
// Identifier = Queue/Process
const identifier = () => `[${[queue.name, name].filter(i => i).join('/')}]`;
const configName = `Tasks.${queue.name}.${name}`;
// Ensure the configs are correct
if (!config.has(configName)) {
logger.info(identifier(), 'SETUP FAILED', 'Task does not have any configs');
return;
}
const { enabled, cron } = config.get(configName);
// Remove previous repeatable jobs
queue.removeRepeatable(name, { cron });
if (!enabled) {
logger.info(identifier(), 'SETUP FAILED', 'Task does not have enabled config');
return;
}
if (!cron) {
logger.crit(identifier(), 'SETUP FAILED', 'Task does not have cron config');
return;
}
logger.info(identifier(), 'SETUP');
// Add the reoccurring task
queue.add(name, null, { repeat: { cron } });
};
await (async () => {
const queue = await createQueue('feed');
const utils = { app, queue };
// Assign the process for this queue
queue.process('fetch', ({ data }) =>
fetchFeed(utils, data),
);
// Schedule reoccurring tasks
scheduleTask(utils, 'fetch');
return queue;
})();
The createQueue
method above calls queue.empty()
internally, so shouldn't that also remove stalled jobs, or any jobs within that queue for that matter?