2

I am trying to use Azure function with to invoke the same function with different time and different param(url). I didn't find any good example that shows how to pass some data. I want to pass link to function. My code is:

var rp = require('request-promise');
var request = require('request');

module.exports = function (context //need to get the url) {  

and the function

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 */1 * * *"
    }
  ],
  "disabled": false
}
Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89
  • 3
    Timer triggered functions use a simple CRON value to indicate how often they should run. They do not allow you to pass any other params besides the TimerInfo. How do you expect to be able to pass a URL? Perhaps you want an HTTP triggered function that will allow you to pass along a value in the request body? – Jesse Carter Jun 08 '17 at 18:35
  • yes. I am trying HTTP trigger, – Vitaly Menchikovsky Jun 08 '17 at 18:52
  • 1
    Then why did you post a function.json for a Timer trigger instead of an HTTP trigger? – Jesse Carter Jun 08 '17 at 19:10
  • Because I thought that Json can be set with variable.i posted my function that should trigger the http ... – Vitaly Menchikovsky Jun 09 '17 at 05:17

2 Answers2

2

If your settings are relatively static (but you still don't want to hard code them), you may use app settings to store them, and then read e.g.

let url = process.env['MyUrl'];

If URL should be determined per request, you may use HTTP trigger and read the URL from query parameters:

let url = req.query.myurl;

I'm not sure what exactly you are trying to achieve with parameterized timer-triggered function.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
0

Another possibility is if your parameters are stored somewhere in e.g. Azure Document DB (Cosmos).

You could still use a TimerTrigger to invoke the function, and include a DocumentDB input binding allowing you to query for the specific parameter values needed to execute the function.

Here's a C# example triggered by Timer, with a DocumentDB input binding. Note: I'm using the latest VS2017 Preview tooling for Azure functions.

[FunctionName("TimerTriggerCSharp")]
public static void Run(
   [TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log, 
   [DocumentDB("test-db-dev", "TestingCollection", SqlQuery = "select * from c where c.doc = \"Test\"")] IEnumerable<dynamic> incomingDocuments) 
 {..}

With the following binding json:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    },
    {
      "type": "documentDB",
      "name": "incomingDocuments",
      "databaseName": "test-db-dev",
      "collectionName": "TestingCollection",
      "sqlQuery": "select * from c where c.docType = \"Test\"",
      "connection": "my-testing_DOCUMENTDB",
      "direction": "in"
    }
  ],
  "disabled": false
}
Garth Mason
  • 7,611
  • 3
  • 30
  • 39