Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect timeout on azure function to reroute message to app service plan

I've got an Azure function unziping archives on a consumption plan. Some of them happens to take more than 10min to unzip and can timeout. I'm thinking of having a separate app service plan where I would reroute the extraction when timing out on consumption plan.

How would you do that? a timer in the function? a catch timeout exception? Do you have a better suggestion?

Thanks

like image 222
Pierre Jeannet Avatar asked Jan 16 '18 15:01

Pierre Jeannet


1 Answers

For those interested I ended adding my own timeout (few seconds earlier than Azure one) to the extract function, then rerouting to another queue handled by a service app plan than don't timeout.

Code :

using (var timeoutCts = new CancellationTokenSource())
{
    try
    {
        // task completed within timeout
        timeoutCts.CancelAfter(590000);
        var counter = await ExtractArchiveAsync(archiveFullName, myBlob, timeoutCts.Token);
        log.Info($"Extracted : { counter.GetCurrentCount() }");
    }
    catch (OperationCanceledException)
    {
        // timeout logic
        log.Info($"Function timedout, redirected to long queue");
        var queue = StorageService.GetCloudQueueReference("ArchiveToExtractQueueTimedOut");
        await queue.AddMessageAsync(new CloudQueueMessage(archiveFullName));
    }
}
like image 117
Pierre Jeannet Avatar answered Oct 03 '22 18:10

Pierre Jeannet