@sidequest/core
Version:
@sidequest/core is the core package of SideQuest, a distributed background job queue for Node.js and TypeScript applications.
39 lines (35 loc) • 1.13 kB
JavaScript
;
var logger = require('../logger.cjs');
var transition = require('./transition.cjs');
/**
* Transition for marking a job as completed.
*
* This transition sets the job state to "completed", records the completion timestamp,
* and stores the result of the job. Completed jobs will not be retried or processed again.
*
* This transition can only be applied to jobs that are currently running.
*/
class CompleteTransition extends transition.JobTransition {
/** The result of the completed job. */
result;
/**
* Creates a new CompleteTransition.
* @param result The result to store in the job.
*/
constructor(result) {
super();
this.result = result;
}
apply(job) {
logger.logger("Core").info(`Job #${job.id} - ${job.class} has completed`);
job.completed_at = new Date();
job.state = "completed";
job.result = this.result ?? null;
return job;
}
shouldRun(job) {
return job.state === "running";
}
}
exports.CompleteTransition = CompleteTransition;
//# sourceMappingURL=complete-transition.cjs.map