Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron expression which run on the last day of the every month

Tags:

cron

azure

webjob

I need to create a cron expression that will run on the every last day of every month. I need this for scheduling the webjob.

I am using this expression but the webjob is not taking L for finding Last day of the every month.

"0 0 11 L * *"

Thanks.

like image 308
Pari Avatar asked Oct 30 '22 03:10

Pari


1 Answers

According to your description, I checked this issue on my side. For a simple way, firstly I tested it on azure portal as follows:

enter image description here

Note: Based on my test, the special characters (?,L,W) for {day} is invalid.

Also, I ran the webjob on my side with the 0/5 * * L * * expression, then I got the following error:

Unhandled Exception: Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.CronJob' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NCrontab.CrontabException: 'L' is not a valid [Day] crontab field expression. ---> NCrontab.CrontabException: 'L' is not a valid [Day] crontab field value. It must be a numeric value between 1 and 31 (all inclusive).

Then I followed this sample TimerSamples.cs and found that we could only override the build-in DailySchedule and WeeklySchedule, but they could not meet your requirement, I assumed that you may need to build your custom schedule inherits TimerSchedule to achieve your purpose.

AFAIK, we could also leverage Azure Scheduler to trigger our webjob on some schedule in addition to set the cron expression with your webjob. Here is my test, you could refer to it:

  • Configure your webjob as manual triggered

  • Log into azure portal, add your Azure Scheduler, then configure the Action settings point to your webjob endpoint that allows is to get triggered. For more details, you could refer to the section about adding a scheduler job in this tutorial

  • Then configure the schedule as follows:

    enter image description here

Additionally, for full cron expression support, you could add your feedback at issues of Azure/azure-webjobs-sdk-extensions.

like image 84
Bruce Chen Avatar answered Nov 07 '22 21:11

Bruce Chen