UNPKG

@sidequest/core

Version:

@sidequest/core is the core package of SideQuest, a distributed background job queue for Node.js and TypeScript applications.

33 lines (29 loc) 1.18 kB
'use strict'; var logger = require('../logger.cjs'); var transition = require('./transition.cjs'); /** * Transition for re-running a job. * This will reset the job to waiting state and ensure it can be executed again. * If the job has reached its maximum attempts, it will increase the max_attempts by 1. * * This transition can only be applied to jobs that are in completed, canceled, or failed states. */ class RerunTransition extends transition.JobTransition { apply(job) { logger.logger("Core").info(`Re-running job #${job.id} - ${job.class}`); // Reset job state to waiting job.state = "waiting"; job.available_at = new Date(); // If the job has reached max attempts, increase max_attempts by 1 if (job.attempt >= job.max_attempts) { job.max_attempts = job.attempt + 1; logger.logger("Core").debug(`Increased max_attempts to ${job.max_attempts} for job ${job.id}`); } return job; } shouldRun(job) { return ["completed", "canceled", "failed"].includes(job.state); } } exports.RerunTransition = RerunTransition; //# sourceMappingURL=rerun-transition.cjs.map