Last active
August 29, 2015 14:16
-
-
Save ctigeek/54d2982c202e166cbca7 to your computer and use it in GitHub Desktop.
Sudo code for scheduling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The idea here is there's a difference between how the event repeats (Repetition) and when that repetition occurs (When/NotWhen). | |
// Between 9am and 6pm, run every 5 minutes, exactly on minute 0,5,10,etc., except on the last day of the month. | |
// Before 9am and after 6pm, run every 10 minutes, exactly on minute 0,10,20, etc, except on the last day of the month. | |
// On the last day of the month, run every 20 minutes, exactly on minute 0,20,40. | |
var config = ScheduleConfig.EveryMinute(5).OnTheMinute(0).When(Between(Hour(9),Hour(18))).WhenNot(DayOfMonth.Last).Named("DayTime") | |
.AddRepetition(Repetition.EveryMinute(10).OnTheMinute(0).When(Before(Hour(9)), After(Hour(18))).WhenNot(DayOfMonth.Last).Named("NightTime") | |
.AddRepetition(Repetition.EveryMinute(20).OnTheMinute(0).When(DayOfMonth.Last).Named("LastDayOfMonth"); | |
var schedule = new Schedule(scheduleConfig); //This could also be IObservable.... | |
var schedule.Occurance += occurance_handler; | |
schedule.Start(); | |
//...... | |
private void Occurance_Handler(object sender, ScheduleOccuranceEventArgs e) { | |
if (e.previousOccurance != Occurance.Never) { | |
var timeSpan = DateTime.Now.Subtract(e.previousOccurance.OccuranceTime); | |
//do stuff.... | |
} | |
if (e.repetition.Name == "DateTime") { | |
// do daytime specific stuff.... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment