Time triggered azure function to trigger immediately after deploy - azure

I have a time-triggered azure function triggered every 1 hour. My requirement is that, it should get triggered every hour but once also immediately after the deployment ?
Is playing with cron expression my only way for this ?

There isn't something directly tied to the deployment. The runOnStartup setting, documented here, triggers your function when the runtime starts, but won't cause the runtime to start as a result of a deployment.
Your best option would likely be to customize your deployment, as documented here, and invoke your function (by issuing an HTTP request) once the deployment completes. You can share the code and have an HTTP triggered function that uses the same logic as the timer function that runs on a schedule.

Related

TimerTrigger doesn't always fire in Azure Functions

I'm experiencing TimerTrigger not actually triggering in multiple of my Azure Functions. The flow always looks similar to this:
As shown in the log statements, this timer is configured to trigger every 5 minutes (0 */5 * * * *). It triggers 5:10, 5:15, ... 5:40. But then on 5:45 no trigger. The same goes for 5:50. Then at 5:51 it "wakes up". I have RunOnStartup = true on my trigger, so this is probably caused by the function app being started.
My function app is consumption based, why I would expect the app to simply run on another machine if the current machine is shot down or in other ways unavailable. The app is running on Azure Functions version 3.
Am I missing something here, or does anyone experience similar issues?
AFAIK, There is no specific reason for the timer trigger not firing properly within the given time.
Few of the workaround we can follow,
I have not faced the similar issue yet, would suggest you to please try to restart/refresh your function app.
or, It may be due to of the sync issue with the function which is not happening properly.
As suggested by #Anand Sowmithiran the SO THREAD, #MayankBargali-MSFT suggest about singleton lock i,e;
TimerTrigger uses the Singleton feature of the WebJobs SDK to ensure
that only a single instance of your triggered function is running at
any given time. When the JobHost starts up, for each of your
TimerTrigger functions a blob lease (the Singleton Lock) is taken.
This distributed lock ensures that only a single instance of your
scheduled function is running at any time. If the blob for that
function is not currently leased, the function will acquire the lease
and start running on schedule immediately. If the blob lease cannot be
acquired, it generally means that another instance of that function is
running, so the function is not started in the current host.
Also please try to set runonstartup to false to check whether its behaving the same or not as provided the MS DOC in comment.
For more information Please refer the below links :-
MS Q&A| Azure Timer Trigger not firing
GitHub | azure timer function not executing all of sudden

Azure durable function replay behavior and time limit for normal http-trigger azure function

Because http-trigger azure function has a strict time limit for 230s, I created a http-trigger durable azure function. I find that when I trigger durable function multiple times and if the last run is not completed, the current run will continue the last run until it is finished. It is a little confused for me because I only want each run to do the task of the current run, not replay the last un-finished run. So my question is that:
Is it by design for durable function to make sure each run is completed (succeed or failed)?
Can durable function only focus on the current run just like the normal http-trigger azure function?
If 2) is not, is there any way to mitigate the time limit issue for normal http-trigger azure function?
Thanks a lot!
The function runs until it gets results that is Successfully completed or failed message.
According to Microsoft-Documentation it says,
Azure Functions times out after 230 seconds regardless of the functionTimeout setting you've configured in the settings.

Timer Trigger Function running long process with Azure Function App with COMSUMPTION plan

I need to develop a process (e.g. Azure fucntion app) that will load a file from FTP once every week, and perform ETL and update to other service for a long time (100mins).
My question is that will Timer Trigger Azure Function app with COMSUMPTION plan works in this scenario, given that the max running time of Azure function app is 10 mins.
Update
My theory of using Timer trigger function with Comumption plan is that if the timer is set to wake up every 4 mins from certain period (e.g. 5am - 10am Monday only), and within the function, a status tells whether or not an existing processing is in progress. If it is, the process continues its on-going job, otherwise, the function exits.
Is it doable or any flaw?
I'm not sure what is your exact scenario, but I would consider one of the following options:
Option 1
Use durable functions. (Here is a C# example)
It will allow you to start your process and while you wait for different tasks to complete, your function won't actually be running.
Option2
In case durable functions doesn't suit your needs, you can try to use a combination of a timer triggered function and ACI with your logic.
In a nutshell, your flow should looks something like this:
Timer function is triggered
Call an API to create the ACI
End of timer function.
The service in the ACI starts his job
After the service is done, it calls an API to remove it's own ACI.
But in anyway, durable functions usually do the trick.
Let me know if something is unclear.
Good luck. :)
With Consumptions plan, the azure function can run for max 10 minutes, still, you need to configure in host.json
You can go for the App Service Plan which has no time limit. Again you need to configure function timeout property in host.json
for more seed the following tutorial
https://sps-cloud-architect.blogspot.com/2019/12/azure-data-load-etl-process-using-azure.html

Azure Function V1 Call another azure function from current azure function

I am using Azure Function V1 c#. I have a time triggered azure function which is checking for some data in my database every second. If the data is found I want to perform some operation on it. This operation can take 30 seconds to 5 minutes depending on the operations happening on it.
When I my time triggered function gets data and starts performing operation on it. Time triggered function is not getting executed again until first operation is completed. So, even if time triggered function is scheduled to be executed every second, it is not getting executed for next 30 seconds if the operation in previous iteration took 30 seconds. How can I solve it?
Can I call some other azure function from current time triggered function that can take care of that 30 sec. running operation and my time triggered function runs smoothly every second?
How can I call another azure function (Custom Function) from current time triggered function?
Thanks,
You may need to consider logic apps for this scenario. Logic Apps are serverless workflow offering from Azure. Use recurrence trigger to schedule the job (http call) and it will trigger the azure function regardless.
https://learn.microsoft.com/en-us/azure/connectors/connectors-native-recurrence
If you want to trigger any external function you may use httpclient.
Azure Functions call http post inside function

Can i execute an on-demand web job from a scheduled webjob?

I need to execute a long running webjob on certain schedules or on-demand with some parameters that need to be passed. I had it in a way where the scheduled webjob would put a message on the queue with the parameters and a queue message triggered job would take over - OR - some user interaction would put the same message on the queue with the parameters and the triggered job would take over. However for some reason the triggered function never-finishes - and right now i cannot see any exceptions being displayed in the dashboard outputs (see Time limit on Azure Webjobs triggered by Queue)
I m looking into whether I can execute my triggered webjob as an On-demand webjob and pass the parameters to it? Is there anyway to call an on-demand web job from a scheduled web job and pass it some command line parameters?
Thanks for your help!
QueueTriggered WebJob functions work very well when configured properly. Please see my answer on the other question which points to documentation resources on how to set your WebJobs SDK Continuous host up properly.
Queue messaging is the correct pattern for you to be using for this scenario. It allows you to pass arbitrary data along to your job, and will also allow you to scale out to multiple instances as needed when your load increases.
You can use the WebJobs Dashboard to invoke your job function directly (see "Run Function" button below) - you can specify the queue message input directly in the Dashboard as a string. This allows you to invoke the function directly as needed with whatever inputs you want, in addition to allowing the function to continue to respond to qeueue messages actually added to the queue.

Resources