[英]Node Azure Function Timer Trigger Always Timesout
我有一個非常簡單的基於節點的 timerTrigger function,它總是達到默認的 5 分鍾超時。 這是從一個更大的 function 開始的,我已經將其縮減為一個簡單的 function,它將當前日期時間記錄到上下文中。
function.json:
{
"bindings": [
{
"name": "notifications",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */2 * * * *"
}
]
}
索引.js:
module.exports = function (context, timer) {
const now = new Date();
context.log(now);
}
Azure 監控:
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
即使這個小例子仍然會超時並關閉 function,從而阻止它按間隔運行。 我已經嘗試通過 VSCode 在本地調試它,並實際將這個 function 部署到 Azure - 每次都有 5 分鍾的超時。 這似乎排除了本地的某些東西,也不應該是代碼問題。
直接來自 MS 文檔的示例類似: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=javascript#example
主持人:
{
"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);
};
有人有什么想法嗎?
我相信我已經找出問題的原因。 在 MS 示例中,導出的 function 以“async”為前綴,而我的不是。
范例:
module.exports = async function (context, myTimer)
我的代碼:
module.exports = function (context, timer)
更改為:
module.exports = async function (context, timer)
添加異步聲明已停止計時器超時。 當然,我必須重寫 function 以使用 await 而不是 old.then/.catch 來停止接收日志警告。
感謝您的閱讀!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.