UNPKG

@jose_velaz/adonisjs-scheduler

Version:
22 lines (21 loc) 812 B
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; }; }