Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I've been working on a dynamic task scheduler based on a Calendar Queue structure and I've hit a bit of a wall. The Calendar Queue lets me enqueue and dequeue events, however I think I might not be understanding the pseudo code correctly, but it can't seem to find any pseudo code referencing the application loop and how the application waits for the correct time before executing the task.

Heres a naiive solution for what I'm talking about:

Let calQueue be a CalendarQueue populated with events.

    time =
    nextTask = calQueue.dequeue()
    if(time!= nextTask.time){

Obviously this has many problems:

  1. many events may occur at the same exact time
  2. the executeTask method may take a significant amount of time to execute, which means events might be missed.
  3. I'm using a database backed CalendarQueue, and so the dequeue method may take a not insignificant time to complete.
  4. This also ignores tasks that were added to the calQueue that must execute before the next task, ie the task was added while it was sleeping, for immediate execution.

Other considerations:

  1. I would like to eventually make this a distributed (clustered) scheduler.
  2. I've looked at cron and fcron but honestly they are both pretty large applications, and somewhat difficult to trace.

Basically what I'm looking for is how I could design a CalendarQueue scheduler.

share|improve this question
Does the language being used have a fork or other threading ability? – MichaelT Sep 10 '13 at 17:51
Do you have a way to wake up the sleep prematurely (like a signal handler)? – MichaelT Sep 10 '13 at 17:55
yeah, I'm currently debating writing the scheduler in C# or Ruby (on a linux machine) so one or the other would be available – Jason Kulatunga Sep 10 '13 at 17:56
C# has a wake from sleep handler I can wake-up early – Jason Kulatunga Sep 10 '13 at 17:57
Taking questions / answers into consideration, why are there problems with 1 or 2? (Or 3 or 4, but those are a different problem) – MichaelT Sep 10 '13 at 18:05

Your Answer


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

Browse other questions tagged or ask your own question.