Isuru
Isuru

Reputation: 970

Azure Function Job that will never executes

I am trying to populate a CRON expression that will pretend to be never executed(at least not in this life time).

I went through this SO question https://stackoverflow.com/questions/8324306/cron-job-that-will-never-execute

But each expression in that question gives an exception Microsoft.Azure.WebJobs.Host: Error indexing method 'Cleanup'. Microsoft.Azure.WebJobs.Extensions: The schedule expression '0 0 5 31 2 ?' was not recognized as a valid cron expression or timespan string.

What are the possible expressions that will fullfill the above mentioned expectation with regard to Azure Functions?

Thank you.

Upvotes: 3

Views: 4724

Answers (3)

user6110389
user6110389

Reputation:

You cannot set never per algorithm, but a leap year with Saturday 29th gives a 28-year gap.

0 0 0 29 Feb Sat

as the first time around this will happen again is 2048.

Good enough?

Upvotes: 17

George Chen
George Chen

Reputation: 14324

Please check the Azure CRON expression, it's:

{second} {minute} {hour} {day} {month} {day-of-week}

And it uses the NCronTab library to interpret CRON expressions. In the github page you could find the value column can have a * or a list of elements separated by commas. That means it doesn't support ?.

So just change your expression to 0 0 5 31 2 * it will be approved. And if you don't your function running you could just disable it. You could refer to this tutorial: How to disable functions in Azure Functions.

Update:

Due to the Function will calculate the Timer to get the function running time and the 2/30 and 2/31 will never come, then it will be in a loop calculation and the year will increase until beyond the limit 9999. In this situation the function will send a exception.

Upvotes: 7

Thili
Thili

Reputation: 768

The main format used for the scheduled WebJob

  • The cron expression is composed of 6 fields: {second} {minute} {hour} {day} {month} {day of the week}.
  • The supported operators are: , - * /
  • Each field can have a specific value (1), a range (1-10), a set of values (1,2,3), all values (), an interval value (/2 == 0,2,4,6,...) or a mix of these (1,5-10).
  • Each value represents a point in time, for example: "5 * * * * *" - means on the 5th second of every minutes --> 00:00:05, 00:01:05, 00:02:05, ... (and not every 5 seconds).

hence according to above rules your cron expression will leads to this error

instead of using 0 0 5 31 2 ? use 0 0 5 31 2 *

Upvotes: 1

Related Questions