Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure functions: Move to poison blob without retry if a particular exception is thrown

I have a blob triggered function, in which a data is deserialized from a Json string and then the further process are done and save the data to db.

My blob trigger function max retry is set as 5. Means if the blob process fails it will retry for 5 times and then move the blob to poison blob.

If the deserialization is failed, then there is no need to retry it for 5 times. So, if the deserialzation exception is thrown I need to move the blob to poison blob without retry. Is there any way to handle this?

like image 853
S M Avatar asked Oct 18 '18 04:10

S M


1 Answers

There is no built-in solution for such case afaik, but you can add an output binding to your poison queue and insert a message manually in the form described here:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#trigger---poison-blobs

The queue message for poison blobs is a JSON object that contains the following properties:

FunctionId (in the format .Functions.)

BlobType ("BlockBlob" or "PageBlob")

ContainerName

BlobName

ETag (a blob version identifier, for example: "0x8D1DC6E70A277EF")

[FunctionName("blobtrigger")]
public static async Task Run(ILogger log, ExecutionContext executionContext,
    [BlobTrigger("blobs/{name}")] Stream blob,
    [Queue("webjobs-blobtrigger-poison")] CloudQueue poisonQueue)
{
    try {
        // do something
        throw new JsonSerializationException();
    }
    catch (JsonSerializationException ex)
    {
        log.LogError(ex, ex.Message);
        await poisonQueue.AddMessageAsync(new CloudQueueMessage()); // your message
    }
}
like image 137
Pawel Maga Avatar answered Oct 29 '22 22:10

Pawel Maga