UNPKG

express-post-task-scheduler

Version:

A lightweight npm package to create and manage scheduled tasks using Express middleware. Configure tasks via POST requests and execute them at specified times seamlessly.

41 lines (40 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScheduleJobs = void 0; /** * Store and control the generated schedule jobs from node-schedule */ class ScheduleJobs { constructor() { /** * The array to store jobs generated by node-schedule's scheduleJob method */ this.jobList = []; } /** * Create or get exist instance of the class */ static init() { if (ScheduleJobs.instance === undefined) { const jobs = new ScheduleJobs(); ScheduleJobs.instance = jobs; } return ScheduleJobs.instance; } /** * Push a new job inside the list from the params and returned instance of node-schedule's scheduler.scheduleJob * @param taskId * @param jobInstance * @param executor */ static appendJob(taskId, jobInstance, executor) { const jobs = ScheduleJobs.init(); jobs.jobList.push({ taskId, jobInstance, executor, }); } } exports.ScheduleJobs = ScheduleJobs; ScheduleJobs.instance = undefined;