Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions Trigger Timer Trigger locally

I have a timerTrigger that I want to locally debug on VS Code, so I do the func host start --debug vscode on the root where host.json is:

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'.

Then I do func run TriggerHR. I get:

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]

Here is the function.json on TriggerHR:

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

I am on v2 runtime. I even try http://localhost:7071/api/myTimer and I get localhost cannot be found even though http://localhost:7071 gives me that smiley face window that my app is running.

Here is how it's laid out:

- TriggerHR (Timer function)
--index.js
--function.json
|
|
- host.json
- local.settings.json
like image 838
test Avatar asked Apr 21 '26 11:04

test


1 Answers

Couple of things:

  1. Make sure you're using the right version of the core tools based on what version of functions you're trying to use. Basically this line Function Runtime Version: 2.0.11370.0 tells you that you're currently running the core tools that target functions v2.

  2. See here for documentation on developing locally.

  3. The core tools for functions v2 do not support the func run command. If you want to test your timer function without waiting for it to run on its schedule, you can use the admin API to invoke it. Try sending a POST request to http://localhost:7071/admin/functions/TriggerHR. See the Non-HTTP triggered functions section in the above doc for more info.

  4. Not sure if you're already trying this, but there is now an extension for VS code designed to make working with azure functions really easy, including debugging. See here.

like image 177
Paul Batum Avatar answered Apr 30 '26 16:04

Paul Batum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!