diff --git a/src/classes/Scheduler.cls b/src/classes/Scheduler.cls new file mode 100644 index 0000000..f80f2b6 --- /dev/null +++ b/src/classes/Scheduler.cls @@ -0,0 +1,28 @@ +/************************************************************************************************* +* This file is part of the Nebula Framework project, released under the MIT License. * +* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. * +*************************************************************************************************/ +public class Scheduler { + //CRON order - Seconds, Minutes, Hours, Day_of_month, Month, Day_of_week, Optional_year + public final static String DAILY_CRON = '0 {0} {1} * * ?'; + public final static String HOURLY_CRON = '0 {0} * * * ?'; + private final Schedulable scheduledClass; + + public Scheduler (Schedulable scheduledClass) { + this.scheduledClass = scheduledClass; + } + + public String scheduleHourly(String jobName, String startingMinuteInHour) { + String hourlyCRON = String.format(HOURLY_CRON, new List{startingMinuteInHour}); + return this.schedule(jobName, hourlyCRON); + } + + public String scheduleDaily(String jobName, List startingHourAndMinute) { + String dailyCRON = String.format(DAILY_CRON, startingHourAndMinute); + return this.schedule(jobName, dailyCRON); + } + + public String schedule(String jobName, String cronExpression) { + return System.schedule(jobName, cronExpression, this.scheduledClass); + } +} \ No newline at end of file diff --git a/src/classes/Scheduler.cls-meta.xml b/src/classes/Scheduler.cls-meta.xml new file mode 100644 index 0000000..8b061c8 --- /dev/null +++ b/src/classes/Scheduler.cls-meta.xml @@ -0,0 +1,5 @@ + + + 39.0 + Active +