简体   繁体   中英

Node Azure Function Timer Trigger Always Timesout

I have a very simple node based timerTrigger function that always hits the default 5 minute timeout. This started on a bigger function that I have whittled down to a simple function that logs the current datetime to context.

function.json:

{
    "bindings": [
        {
            "name": "notifications",
            "type": "timerTrigger",
            "direction": "in",
            "schedule": "0 */2 * * * *"
        }
    ]
}

index.js:

module.exports = function (context, timer) {
    const now = new Date();
    context.log(now);
}

Azure Monitor:

2022-03-03 17:25:51.279 Executing 'Functions.app-notifications' (Reason='Timer fired at 2022-03-03T17:25:51.2788686+00:00', Id=085ddbca-ed47-4757-89f7-daffd40701b5) Information
2022-03-03 17:25:51.295 3/3/2022 5:25:51 PM Information
2022-03-03 17:30:51.382 Timeout value of 00:05:00 exceeded by function 'Functions.app-notifications' (Id: '085ddbca-ed47-4757-89f7-daffd40701b5'). Initiating cancellation. Error
2022-03-03 17:30:51.430 Executed '{functionName}' ({status}, Id={invocationId}, Duration={executionDuration}ms) Error
2022-03-03 17:30:51.430 Executed 'Functions.app-notifications' (Failed, Id=085ddbca-ed47-4757-89f7-daffd40701b5, Duration=300104ms) Error
2022-03-03 17:30:51.431 Error

Even this tiny example still hits the timeout and shuts down the function, preventing it from running at the intervals. I have tried debugging this both locally through VSCode and actually deploying this function to Azure - each end up with a 5 minute timeout. This seems to rule out something locally and also shouldn't be a code issue.

The example straight from MS docs is similar: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=javascript#example

host:

{
    "schedule": "0 */5 * * * *",
    "name": "myTimer",
    "type": "timerTrigger",
    "direction": "in"
}

function:

module.exports = async function (context, myTimer) {
    var timeStamp = new Date().toISOString();

    if (myTimer.isPastDue)
    {
        context.log('Node is running late!');
    }
    context.log('Node timer trigger function ran!', timeStamp);   
};

Does anyone have any ideas?

I believe I have figured out the reason to my issue. In the MS example, the exported function is prefixed with 'async', mine is not.

MS Example:

module.exports = async function (context, myTimer)

My code:

module.exports = function (context, timer)

changing to this:

module.exports = async function (context, timer)

Adding the async declaration has stopped the timer timeouts. Of course, I have to rewrite the function to use await instead of the old.then/.catch in order to stop receiving the log warnings.

Thank you for reading!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM