@jose_velaz/adonisjs-scheduler
Version:
Task scheduler for AdonisJS
22 lines (21 loc) • 812 B
JavaScript
import { ScheduleCommand, Scheduler } from './scheduler.js';
import { arrayWrap } from './utils.js';
export function schedule(expression, args = [], name) {
return function (target) {
if (typeof expression === 'string') {
const scheduleCommand = new ScheduleCommand(target.commandName, arrayWrap(args)).cron(expression);
if (name) {
scheduleCommand.as(name);
}
Scheduler.__decorator_schedules.push(scheduleCommand);
}
else {
const scheduleCommand = new ScheduleCommand(target.commandName, arrayWrap(args));
if (name) {
scheduleCommand.as(name);
}
Scheduler.__decorator_schedules.push(expression(scheduleCommand));
}
return target;
};
}