Sknecht
Sknecht

Reputation: 1074

Azure Webjobs ignores CRON expression

I have a program that I want to run once per day. I put my program.exe and my settings.job in one zip file and uploaded it. I sat the running mode to continuous. My settings.job looks like:

{
   "schedule": "0 0 8 * * *"
}

My plan was that it runs every day at 8 but instead it runs repeated all the time over and over again. What did I do wrong?

Upvotes: 5

Views: 5629

Answers (2)

After days of trying unsuccessfully to make the elusive Azure WebJob run on a CRON expression following the top online tutorials:

I finally managed to make my jobs run on cron schedules.

For me the settings.json in the root folder never worked. What did work and was actually extremelly straightforward to implement was to use the Azure Webjobs SDK Extensions. This approach gives you the most flexibility in implementing the scheduling, it is very well documented and there are complete sample projects for it: https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/ExtensionsSample/Samples/TimerSamples.cs

With a function definition as simple as this you can be up and running with cron scheduling:

public static void CronJob([TimerTrigger("0 */5 * * * *")] TimerInfo timer) { Console.WriteLine("Cron job fired!"); }

The Webjobs extensions also open up a whole world of other possibilities so they are 100% worth checking out if you are using Azure Webjobs: https://github.com/Azure/azure-webjobs-sdk-extensions

Upvotes: 5

Thomas
Thomas

Reputation: 29522

You webjob running mode should be On Demand:

From the documentation :

  • You still need Always On setting to be enabled on the app.
  • Note: when deploying a WebJob from Visual Studio, make sure to mark your settings.job file properties as 'Copy if newer'.

Upvotes: 6

Related Questions