azureazure-webjobsazure-webjobssdkalwaysonazure-webjobs-continuous

Azure WebJob sudden shutdown while processing


I have a continuous Azure WebJob, that is set to 'Always On'. This WebJob is supposed to handle new messages being added to a storage queue.

I'm wondering what if for some reason the WebJob has stopped working while it was processing a queue trigger. This way I will lose the message from the queue, and it won't go to poison queue.

How can I workaround this?


Solution

  • I'm wondering what if for some reason the WebJob has stopped working while it was processing a queue trigger.

    Firstly, if the WebJob would exit while process message, you don't have to worry about corrupted data. When the WebJob access the message to process, it will hide the message in the queue for a certain amount time. If your WebJob shut down while process the message, the message will be available again after the time, and it will be re-grabbed and ran against the updated code.About the details, you could refer to this answer.

    As for your requirement about being notified the job is shutting down. You could use Graceful Shutdown and listen to CancellationToken you can pass to you triggered function and judge the property IsCancellationRequired value , then you could handle the WebJob would shut down. Here is the sample code about CancellationToken.