I have written following functions in continuous web job :
public static void fun1([TimerTrigger("24:00:00", RunOnStartup = true, UseMonitor = true)] TimerInfo timerInfo, TextWriter log)
{//Code}
public static void fun2([TimerTrigger("00:01:00", RunOnStartup = true, UseMonitor = true)] TimerInfo timerInfo, TextWriter log)
{//code}
where, fun1 is not getting called again (only once, after starting web job) and fun2 is getting called with 1 min trigger after every process gets completed.
can anyone please explain why? Am I doing anything wrong?
Azure WebJobs are deprecated, but still in use. They are being phased out in favor of Azure Functions. Azure Functions is a more up-to-date and feature rich service which offers a greater degree of flexibility and control.
WebJobs is an Azure App Service feature that allows you to execute a program or script in the same instance as a web app, API app, or mobile app. Continuous WebJobs are launched as soon as they're created, and they run in an infinite loop.
You should have a look at the documentation of the TimerTriggerAttribute
:
A Cron expression can be represented like that:
* * * * * * command to be executed
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ └───── day of week (0 - 7) (0 or 7 are Sunday, or use names)
│ │ │ │ └────────── month (1 - 12)
│ │ │ └─────────────── day of month (1 - 31)
│ | └──────────────────── hour (0 - 23)
│ └───────────────────────── min (0 - 59)
└────────────────────────────── second(0 - 59)
In you case, the expression is a string represening a TimeSpan :
"24:00:00"
: this job is running every 24 hours, RunOnStartup
: this means the job will run when the webjob starts or restarts even if the last run occured in the last 24 hours.
"00:01:00"
: this job is running every minute, RunOnStartup
: this means the job will run when the webjob starts or restarts even if the last run occured in the last minute.
EDIT
From this answer:
This is due to the way TimeSpan.Parse works. If you pass it "24:00:00" strangely enough it will give you back a TimeSpan of duration 24 days. Not sure if this is their intended behavior or a bug on their side, but we simply pass the expression down to them and inherit their behavior. Anyhow, for your purposes, to get 24 hours you can use "1.00:00" (specifying 1 day).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With