Azure计时器触发功能根本不执行脚本日志

时间:2020-03-13 22:46:39

标签: azure-functions

我正在使用测试模板测试计时器触发功能,并且无法执行脚本和任何日志,因为“ JavaScript计时器触发功能已运行!”。它以前对我有用,但是第二天它根本不执行该脚本,而该函数本身似乎正在运行,但是我无法测试该脚本并且不了解问题所在。 我的function.js文件

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 * * * * *",
      "runOnStartup": true
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "githubKey": "sample123"
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*",
    "CORSCredentials": false
  }
}

这就是我的终端机中的

RFC3987

index.js

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

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

1 个答案:

答案 0 :(得分:0)

我可以重现您的问题,然后在github中找到相同的问题:Improve Timer trigger behavior with host lock

enter image description here

这是由Singleton Lock引起的,您可以参考以下详细信息:Singleton Locks,在“本地开发”下显示为:

ListenerLockPeriod的默认值为60秒,这意味着 主机被恶意破坏(例如,在以下情况下关闭控制台窗口) 在本地运行)无法重新获取已持有的Blob租约 直到租约自然到期为止。这意味着如果您杀死一个 正在运行的实例,然后尝试立即重新启动JobHost, 您会看到该函数不会立即开始运行,因为 等待获取Singleton锁。

假设这是造成您问题的原因,因此在github问题中,有一个solution,请在host.json中设置listenerLockPeriod

以下是示例:

"singleton": {
    "listenerLockPeriod": "00:00:15" 
  }

enter image description here