Skip to content

Commit 8824eae

Browse files
committed
2 parents a8b818a + 416ad7c commit 8824eae

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

README.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,73 @@
1-
Scheduler
2-
=========
1+
## Scheduler
2+
Scheduler is a small and fast utility that takes a schedule and determines the next DateTime that matches the schedule, from a given starting DateTime. The current release only includes a cron style schedule parser, but the engine is flexible enough to allow for other ways of defining these schedules. The strategy used by this scheduler is such:
33

4-
Scheduler
4+
* Schedules are broken into a series of schedule entries. These entries can be defined as a series of values, or ranges, and an interval. The series of values are further refined by the interval - I.E. the value must be evenly divisible by the interval to be included.
5+
* Schedules consist of schedule entries for minute, hour, day of month, month and day of week.
6+
* The engine searches on the largest values first, then checking each smaller value, only checking valid values for each schedule entry. For example, the engine first iterates over the months until it finds a valid month, then over the days, hours and minutes in that order, allowing for a very fast resolution of the schedule.
7+
8+
## Cron Schedules
9+
Cron schedules allow for defining advanced schedules down to the minute. This style of scheduling is used predominately in Linux environments, but is a very powerful and simple method of specifying a schedule. The format for a cron schedule is shown here:
10+
11+
* * * * *
12+
│ │ │ │ │
13+
│ │ │ │ │
14+
│ │ │ │ │
15+
│ │ │ │ └───── Day of Week (0 - 6) (Sunday = 0)
16+
│ │ │ └────────── Month (1 - 12)
17+
│ │ └─────────────── Day of Month (1 -31)
18+
│ └──────────────────── Hour (0 - 23)
19+
└───────────────────────── Minute (0 - 59)
20+
21+
### Special Characters
22+
The special characters allowed in the schedule entries for the schedule include:
23+
* Asterisk ( * )
24+
The asterisk indicates that the expression matches for all values of the
25+
field, for example, using an asterisk in the 4th field (month) indicates
26+
every month.
27+
* Slash ( / )
28+
Slashes describe increments of ranges. For example 0/15 in the 1st field
29+
(minutes) indicates the 0th (top) minute of the hour and every fifteen
30+
minutes thereafter.
31+
* Comma ( , )
32+
Commas are used to separate items of a list. For example, using
33+
"MON,WED,FRI" in the 5th field (day of week) means Mondays, Wednesdays and
34+
Fridays.
35+
* Hyphen ( - )
36+
Hyphens define ranges. For example, 8-10 indicates every month between
37+
August and October, inclusive.
38+
39+
### Sample Schedules
40+
`30 0 1 1,6,12 *` - 00:30 on 1st of Jan, Jun & Dec
41+
`0 20 * 10 1-5` - 20:00 every weekday in Oct
42+
`0 0 1,10,15 * *` - Midnight on 1st, 10th & 15th of month
43+
`5,10 0 10 * 1` - At 00:05 and 00:10 every 10th of the month that is also a Monday
44+
`*/15 0-6/2 * MON-FRI` - Every 15 minutes on even hours between 12 and 6 AM on weekdays
45+
46+
## Usage
47+
Using the Scheduler is quite simple. Let's just dig into some samples:
48+
49+
### Example 1
50+
Here we parse a schedule ahead of time. This is helpful if you are reusing a schedule. This is the suggested way:
51+
52+
Schedule schedule = ScheduleParser.ParseSchedule("*/15 0-6/2 * * MON-FRI");
53+
DateTime example1 = Scheduler.GetNext(schedule);
54+
Console.WriteLine(String.Format("Example 1: {0}", example1));
55+
56+
The result:
57+
58+
Example 1: 11/24/2014 12:00:00 AM
59+
60+
### Example 2
61+
If you are in a bit more of a hurry, a shortcut is included on the Scheduler:
62+
63+
DateTime example2 = Scheduler.GetNext("*/7 * * * *");
64+
Console.WriteLine(String.Format("Example 2: {0}", example2));
65+
66+
The result:
67+
68+
Example 2: 11/22/2014 4:56:00 PM
69+
70+
## NuGet
71+
The package will be released to NuGet as "PointerPlace.Scheduler"
72+
73+
**Enjoy!**

0 commit comments

Comments
 (0)