Reputation: 153
Is it possible to schedule a function in azure to run every second week on a specific day of the week, example Monday? Or at least to run on the first Monday of every month?
I try something like
0 0 1-7,15-21 1 * 1
but it runs on every 1-7 and 15-21 AND Mondays. I want to change that for 1-7 and 15-21 that IS Monday.
Upvotes: 1
Views: 1634
Reputation: 387
I couldn't think of a way to do what you are asking "elegantly". It does look like Azure accepts TimeSpan strings as inputs. So if you wanted your function to run every two weeks (not a specific day of the week) you can use the following:
[TimerTrigger("14.00:00:00")]
If you wanted to run every 2 weeks starting on a specific day of the week, you can simply publish your function on the specific day of the week that you are concerned with.
Let's say you also wanted to run your function the day that you published it, you can set your TimerTrigger
like so:
[TimerTrigger("14.00:00:00", RunOnStartup = true)]
then publish your function the same day.
This is more of a hack to do what you are asking, 8 months later this is all you've got :)
If you wanted to do this a little more programmatically, you could use a TimerTrigger
like
[TimerTrigger("0 0 0 * * Monday")]
the when your function executes, check if you are on a even or odd numbered week and return early - effectively running once every two weeks:
if ((DateTime.Now.DayOfYear / 7) % 2 == 0) return;
Upvotes: 2