Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created July 16, 2012 21:29
Show Gist options
  • Save prabirshrestha/3125185 to your computer and use it in GitHub Desktop.
Save prabirshrestha/3125185 to your computer and use it in GitHub Desktop.
azure job scheduling with queues
var job = new Job {
Cron = "* * * * *",
Name = "job1",
CancellationToken = CancellationToken.None,
AutoRun = true, // run once when scheduler starts then use the cron to schedule
Execute = j => Console.Run("running job");
};
var scheduler = new Scheduler();
scheduler.Add(job);
scheduler.Add(job1);
scheduler.Run();
// scheduler.Run method impl for 1 job: todo support multiple jobs
while(true) {
await Task.Delay(job.GetNextRunSchedule()); // GetNextRunSchedule() returns timespan.
await queue.AddMessageTaskAsync(job.ToQueueMessage()); // todo: implement retry logic
}
// use https://gist.github.com/3093080 Azure Queue Batch Poller to process the queue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment