Reputation: 14320
How could I create an timer trigger with Azure Functions (version 3 and .NET Core) that must be executed every first Tuesday from every month at 8 AM. Starting from now (05/08/2020) this must be the next five occurrences:
By using www.cronmaker.com, I've next NCRONTAB:
0 0 8 ? 1/1 TUE#1 *
But then I've next exception:
The schedule expression
0 0 8 ? 1/1 Tue#1 *
was not recognized as a valid CRON expression or TimeSpan string.
Then I've start changing the CRON expression to next varations:
CORN | Result |
---|---|
0 0 8 ? 1/1 Tue#1 |
Error from above |
0 0 8 * 1/1 Tue#1 |
Error from above |
0 0 8 1/1 Tue#1 * |
Error from above |
0 0 8 * 1/1 Tue 1 |
Error from above |
0 0 8 ? 1/1 Tue 1 |
Error from above |
0 0 8 * 1/1 Tue/1 |
2020/05/29 08:00:00 - 2020/05/30 08:00:00 |
0 0 8 * * Tue/2 |
2020/05/30 08:00:00 - 2020/06/02 08:00:00 |
0 0 8 * 1/1 Tue/2 |
2020/05/30 08:00:00 - 2020/06/02 08:00:00 |
0 0 8 ? 1/1 Tue/2 |
Error from above |
So every expression I've made, would not work as expected. My question is now: What's the correct expression?
Upvotes: 1
Views: 1832
Reputation: 14334
The first Monday of the month falls on one (and only one) of the dates from the first to the 7th inclusive. Then the cron expression will be easy to get it.
Suppose it should be 0 0 8 1-7 * Tue
and the below is my test, it shows the first five dates.
Upvotes: 3
Reputation: 4384
Unfortunately the timer trigger uses the NCrontab library, which doesn't have the concept of "first Tuesday". I think the best you can do is to set the expression to 0 0 8 * * 2
to trigger at 8am every Tuesday and have a bit of code in the actual function that returns immediately if it's not the first Tuesday of the month.
Upvotes: 1