How to define retry policy for Azure Function Timer trigger - NodeJs v4

Gagandeep Singh 0 Reputation points
2024-01-10T17:54:29.71+00:00

I'm new to Azure and looking to define retry policies for my function app timer trigger in Nodejs v4. I could not find documentation defining the configuration in V4 model, though it is possible to define in V3 model in function.json file that V4 does not support. https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-node-js-v4-programming-model-is-generally/ba-p/3929217

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MikeUrnun 9,777 Reputation points Moderator
    2024-01-23T23:39:22.8766667+00:00

    Hello @Gagandeep Singh - Thanks for confirming in the comments. The retry policy for Time Triggers is a GA feature, and it can be configured in the v4 programming model of NodeJS. Based on the TimerFunctionOptions type, which is found here, you can pass in RetryOptions object (describing the retry policy) to retry as follows:

    const { app } = require('@azure/functions');
    
    app.timer('timerTrigger', {
        schedule: '0 */5 * * * *',
        handler: (myTimer, context) => {
            context.log('Timer function processed request.');
        },
        retry: {
            strategy: 'fixedDelay',
            maxRetryCount: 3,
            delayInterval: 300
        }
    });
    

    Config object for exponentialBackoffpolicy can be found here: https://github.com/Azure/azure-functions-nodejs-library/blob/aa9068df56c2d4c2b90ee55dd42005e1d7c5cb4c/types/index.d.ts#L142

    UPDATE 2/7/24: If the function execution does not complete the schedule will not be updated so the timer will be seen as past due. The following note in the TimerTrigger doc is still valid in this case:
    User's image


    Please "Accept Answer" if the answer is helpful so that others in the community may benefit from your experience.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.