我想要在VS Code上进行本地调试timerTrigger
,所以我在func host start --debug vscode
所在的根上执行host.json
:
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
答案 0 :(得分:4)
一些事情:
确保根据您尝试使用的功能版本使用正确版本的核心工具。基本上,这一行Function Runtime Version: 2.0.11370.0
告诉您,您当前正在运行针对函数v2的核心工具。
有关本地开发的文档,请参阅here。
函数v2的核心工具不支持func run
命令。如果要测试计时器功能而不等待其按计划运行,可以使用admin API来调用它。尝试向http://localhost:7071/admin/functions/TriggerHR
发送POST请求。有关详细信息,请参阅上述文档中的Non-HTTP triggered functions
部分。
不确定您是否已经尝试过这个,但现在有一个VS代码的扩展,旨在使用azure函数非常简单,包括调试。请参阅here。
答案 1 :(得分:0)
试试看:
[FunctionName("YourFunctionName")]
public async Task Run([TimerTrigger("0 30 17 * * *"
#if DEBUG
,RunOnStartup = true
#endif
)] TimerInfo myTimer, ILogger log)
{
//your code
}