Pitamber Tiwari
Pitamber Tiwari

Reputation: 536

Re-run the azure webjobs after it fails with exception for N number of times

I've a web job that grab a file from internet and process it. I have tied it s to a scheduler that run everyday at the mid-night.

Sometimes the grab file process fails and throws an exception which crashes the web jobs and stops till the scheduler kicks again next day.

To stop the app from crashing, one option I have is to wrap it with a try-catch block and handle the error. But I want to be able to re-run the web jobs after it fails.

Is there a way for me to tell the azure scheduler to re-run the task for N number of times after it fails?

For example, I want the web jobs to be re-run after 5 minutes of fail for at-most 5 times. I don't want to wait for the scheduler to kick in next day.

Upvotes: 3

Views: 1348

Answers (1)

rnrneverdies
rnrneverdies

Reputation: 15627

Is there a way for me to tell the azure scheduler to re-run the task for N number of times after it fails?

Azure Scheduler does not provide a way to verify if the "remote" execution succeeded or not, but you can use a "Storage Queue" Action Type to put a message into a specified queue and achieve the same behavior in the web job itself. The Azure Web Jobs SDK will process the incoming message and retry up to 5 times if an exception is thrown, also the queue processor is extensible (since 1.1), so you can easily implement an exponential retry policy or whatever policy you need (by extending QueueProcessor and QueueProcessorFactory classes).

Steps:

  1. Update your actual web job to consume a queue (by using [QueueTrigger("myqueue")]), and configure it as "Continuous Running" (in the VS project and the azure Web App).
  2. Create a Azure Scheduler Job of type "Storage Queue", this will push a message into the mentioned queue.

enter image description here

note: this option requires Standard Tier in your Web App (due "Continuous Running")

Upvotes: 4

Related Questions