【问题标题】:Azure Functions Trigger Timer Trigger locallyAzure Functions Trigger Timer 本地触发器
【发布时间】:2017-11-28 22:27:03
【问题描述】:

我有一个 timerTrigger,我想在 VS Code 上进行本地调试,所以我在 host.json 所在的根目录上执行 func host start --debug vscode

PS C:\Users\user\code\azure\functions> func host start --debug vscode

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

[11/28/2017 10:21:30 PM] Reading host configuration file 'C:\Users\user\code\azure\functions\host.json'
[11/28/2017 10:21:30 PM] Host configuration file read:
[11/28/2017 10:21:30 PM] {}
info: Worker.Node.1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2[0]
      Start Process: node  --inspect=5858 "C:\Users\user\.azurefunctions\bin\workers\node\dist\src\nodejsWorker.js" --host 127.0.0.1 --port 59865 --workerId 1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2 --requestId f52eeb9b-d46b-4791-8504-3f94f380c1e2
[11/28/2017 10:21:31 PM] Generating 1 job function(s)
[11/28/2017 10:21:31 PM] Starting Host (HostId=swlaptop2062-377256582, Version=2.0.11370.0, ProcessId=16752, Debug=True, ConsecutiveErrors=0, StartupCount=0, FunctionsExtensionVersion=)
[11/28/2017 10:21:31 PM] Found the following functions:
[11/28/2017 10:21:31 PM] Host.Functions.TriggerHR
[11/28/2017 10:21:31 PM]
info: Worker.Node.1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2[0]
      Debugger listening on ws://127.0.0.1:5858/77692ee0-e279-4463-9974-f8412f5dd3fd
info: Worker.Node.1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2[0]
      For help see https://nodejs.org/en/docs/inspector
Listening on http://localhost:7071/
Hit CTRL-C to exit...
launch.json for VSCode configured.
info: Worker.Node.1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2[0]
      Worker 1b2b2430-8e1c-4d66-a3e9-bb1672be5ac2 connecting on 127.0.0.1:59865
[11/28/2017 10:21:32 PM] Job host started
[11/28/2017 10:21:32 PM] Host lock lease acquired by instance ID '000000000000000000000000EF9214DA'.

然后我做func run TriggerHR。我明白了:

Error: unknown argument run
Azure Functions Core Tools (2.0.1-beta.21)
Function Runtime Version: 2.0.11370.0
Usage: func [context] [context] <action> [-/--options]

这是function.json 上的TriggerHR

{
  "disabled": false,
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */30 * * * *"
    }
  ]
}

我在 v2 运行时。我什至尝试http://localhost:7071/api/myTimer 并得到localhost cannot be found,尽管http://localhost:7071 为我提供了我的应用正在运行的笑脸窗口。

这是它的布局方式:

- TriggerHR (Timer function)
--index.js
--function.json
|
|
- host.json
- local.settings.json

【问题讨论】:

    标签: azure-functions


    【解决方案1】:

    几件事:

    1. 确保根据您尝试使用的功能版本使用正确版本的核心工具。基本上,Function Runtime Version: 2.0.11370.0 这一行告诉您,您当前正在运行针对函数 v2 的核心工具。

    2. 有关本地开发的文档,请参阅 here

    3. 函数 v2 的核心工具不支持 func run 命令。如果您想测试您的计时器功能而不等待它按计划运行,您可以使用管理 API 来调用它。尝试向http://localhost:7071/admin/functions/TriggerHR 发送 POST 请求。有关详细信息,请参阅上述文档中的 Non-HTTP triggered functions 部分。

    4. 不确定您是否已经尝试过,但现在有一个 VS 代码扩展,旨在使使用 azure 函数变得非常容易,包括调试。见here

    【讨论】:

    • 1.是的,我使用的是@core 版本。 2. 是的,我读到了。 3. 我正在使用 POSTMAN 向http://localhost:7071/admin/functions/myTimerhttp://localhost:7071/admin/functions/TriggerHR 发送POST 请求,但没有成功。 4. 是的,我已经安装了。
    • “没有运气”是什么意思? HTTP 响应代码是什么?
    • 对于现在看到这个的任何人来说,我遇到了与@nn2 相同的问题 - 包括一个空的 json 主体修复了它(即 {} )
    • 同样的问题,管理员/功能的帖子不起作用。我收到 400 错误:stackoverflow.com/questions/55063821/…
    • 正如 Esben 所建议的,在使用 curl 时使用不带引号的 epty {} 会有所帮助:curl --request POST -H "Content-Type:application/x-www-form-urlencoded" --data {} http://localhost:7071/admin/functions/MainTriggerEntry。看看我们如何不用双引号将 {} 括起来
    【解决方案2】:

    试试看:

    [FunctionName("YourFunctionName")]
        public async Task Run([TimerTrigger("0 30 17 * * *"
            #if DEBUG
            ,RunOnStartup = true
            #endif
            )] TimerInfo myTimer, ILogger log)
        {
           //your code
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-26
      • 2022-01-19
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      • 2017-10-29
      相关资源
      最近更新 更多