Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
335 stars 103 forks source link

Manually marking Service Bus Queue Function as Failed #1383

Open garoplin opened 9 months ago

garoplin commented 9 months ago

Is your question related to a specific version? If so, please specify: Programming Model V1, Azure FUnction v4, python 3.10

What binding does your question apply to, if any? (e.g. Blob Trigger, Event Hub Binding, etc) Service Bus Queue

Question

Currently I have policy of retrying setup on function and Service Bus level. When the processing throws an error the message goes back to queue 3 times as expected (defined by property Max delivery count). However, for some types of exceptions I don't want to retry processing, because I know the retry won't help and it's pointless to waist computing power for that. So I can't catch the exception on the top level, check whether I should retry or no. The problem is that I still want to throw that exception after catching it, so the function execution will be marked as failed. Is there any way to mark the message as completed and then throw the exception? Or to silence the exception but add some kind of property to function execution context, so that it will be visible as failed?

vijaystroup commented 9 months ago

Facing this issue right now with local testing. Tried just raising an Exception but that causes the function to fire immediately again ignoring the message lock. ~One solution I found for now is marking a function as failed by doing sys.exit(0) which seems to have the desired outcome but this produces a weird start-up traceback but after will perform as expected. I don't feel comfortable doing this thought because I do not know what it will do when deployed.~ From the above the function is executing when the message should be unlocked but it does not run properly (does not actually execute the contents of the function). Work around for now is just to manually add back in a message to the queue.

There should be a functionality like in c# to be able to set autoComplete to False or a special exception in the azure.functions.ServiceBus class that a service bus trigger will listen to and mark it as a failed function without trying to retry the function again.

garoplin commented 8 months ago

Any update on this?

JanuszNowak commented 8 months ago

Any update on this ?

andreyshv commented 7 months ago

The only solution i've found for now is to move message to dead letter queue and then rethrow exception. This sample can help