Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm spec'ing out a API for a task scheduler and I would be thankful for your thoughts. This is what I've got so far:

public void Configure(Context ctx) {
    // Single tasks
    ctx.Run(() => Tasks.First()).Every.Midnight;
    ctx.Run(() => Tasks.Second()).Every.Day(8,0));

    // Multiple tasks
    ctx.Run(() => {
        Tasks.Third();
        Tasks.Fourth();
    }).Every.Day(8,0);

   // Triggers:
   ..Every.Hour(20/*Minute*/);
   ..Every.Minute(10/*Second*/);
   ..Every.Second();
}

The run method accepts an Action parameter.

Obviously, I need to support custom triggers to allow users to configure it exactly as they want. It could be done by implementing an interface like:

interface ITask {
    bool ShouldRun(DateTime currentDate);
}
share|improve this question
1  
I wouldn't bother with all your various every overloads, if you want fluent style replace the everys with a single method .AndReoccur(int numberOfTimes, Timespan interval) also I'm pretty sure this site is supposed to be for compilable functioning code, maybe this fits on stackoverflow better? – Jimmy Hoffa Aug 12 '11 at 1:59

Instead of rolling your own API for repetitions, I'd adopt the terminology and semantics of RFC 5545 RRULEs which is widely used within Calendaring applications

Section 3.8.5.3 thoroughly documents the syntax and behavior of RRULEs (Recurrence rules). They look like

RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH

which means

Weekly on Tuesday and Thursday for five weeks:

so you could implement these semantics (or find an existing RFC 5545 library that does it) and your API might look very similar to the RRULE syntax:

ctx.Run(...).Freq(WEEKLY).Count(10).ByDay(TU, TH)
share|improve this answer

I'd like to be able to use a non-functional approach to running the api. Perhaps I'm a new developer and don't understand lambdas. Give me the option to go.

ctx.Run(//Task, or List of tasks,  //How often, //Time to start, //Possible skip conditions - maybe skip weekends);

//Utilize enums that they can use
ctx.Run(Task.First(), Frequency.Daily, Time.Midnight);

//or pass a list of tasks perhaps
List<Task> tasks;
ctx.Run(tasks, Frequency.Hourly, Time.Custom(hour, min, sec), Time.Weekends);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.