Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Fixes issue #42 - scheduler class with simple CRON scheduling methods
Browse files Browse the repository at this point in the history
  • Loading branch information
James Simone committed Jul 21, 2017
1 parent 289ce88 commit 1b77de5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/classes/Scheduler.cls
Original file line number Diff line number Diff line change
@@ -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<String>{startingMinuteInHour});
return this.schedule(jobName, hourlyCRON);
}

public String scheduleDaily(String jobName, List<String> 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);
}
}
5 changes: 5 additions & 0 deletions src/classes/Scheduler.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>39.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 1b77de5

Please sign in to comment.