Search code examples
azure.net-coreazure-webjobswebjobazure-webjobs-continuous

WebJobs SDK 3 Braking on Function Exception


I have an Azure WebJob (.NET Core - SDK 3) that is braking when an execution of queue triggered function fails. I would like this WebJob to behave like others WebJobs (SDK 2 - .NET Framework) I have running on Windows WebApps.

When execution of queue triggered functions fail on WebJobs SDK 2 (Windows WebApp) the message is sent back to queue with DequeueCount incremented and after X times (default is 5) message is sent to poison queue. And the WebJob always keeps running.

Is it possible to have same behavior with WebJobs SDK 3? This is an example of described bahavior (webjobs.ricardogaefke.com). In this case I needed to use a try/catch and manually send the message to poison queue and it is a waste of the power of webjobs (retry is lost this way).

Thank you very much.


Solution

  • I found the solution using FunctionExceptionFilterAttribute. Functions' filters are similar to ASP.NET MVC filters and in my case I can handle error in My WebJob's functions and return a completed Task even on error, so the message is sent back to queue with DequeueCount++ (till the limit of dequeues - default is 5).

    The final solution can be found at webjobs.ricardogaefke.com and there is a How it works page with links to GitHub repo, public Azure Pipelines and public Docker registry.