3

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.

rnrneverdies
  • 15,243
  • 9
  • 65
  • 95
Pitamber Tiwari
  • 536
  • 1
  • 6
  • 19

1 Answers1

4

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")

rnrneverdies
  • 15,243
  • 9
  • 65
  • 95
  • What if I'm not using a queue? What I was trying to do was move my windows service to azure webjobs without using any messaging queues. So far I have been able to implement [http://stackoverflow.com/questions/1563191/c-sharp-cleanest-way-to-write-retry-logic](http://stackoverflow.com/questions/1563191/c-sharp-cleanest-way-to-write-retry-logic), – Pitamber Tiwari Sep 28 '15 at 16:25
  • Btw, take a look to https://msdn.microsoft.com/en-us/library/microsoft.practices.transientfaulthandling.aspx – rnrneverdies Sep 28 '15 at 16:46