UNPKG

@sidequest/core

Version:

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

37 lines (34 loc) 1.08 kB
import { logger } from '../logger.js'; import { JobTransition } from './transition.js'; /** * 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 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("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"; } } export { CompleteTransition }; //# sourceMappingURL=complete-transition.js.map