Search code examples
azureazure-functionscron-task

How to call azure function with params


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
}

Solution

  • 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
    }