Have Azure Webjob Function run once on startup

996 Views Asked by At

Is there a specific way to have Azure WebJobs trigger a function once on startup without using external messages/triggers? I know there is the RunOnStartup annotation that can be added to the TimerTrigger trigger but that still requires a time interval to run the function on. In my case, I am simply looking to run the function once on the startup.

2

There are 2 best solutions below

0
On

Thanks for asking question! Azure WebJob is known for its ‘Event-driven background processing’ method. Further, WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app. To elaborate on this there are continuous and triggered types of Web Jobs. The continuous type; Starts immediately when the WebJob is created. To keep the job from ending, the program or script typically does its work inside an endless loop. If the job does end, you can restart it. But triggered type Starts only when triggered manually or on a schedule.

Check this link on creating scheduled web job: https://learn.microsoft.com/en-us/azure/app-service/webjobs-create#CreateScheduledCRON

0
On

WebJobs have two types: Continuous and Triggered.

Here is a table describes the differences between continuous and triggered WebJobs. enter image description here

If you just want your task run once, you could set it triggered manually. Follow this turorial: Create a manually triggered WebJob