skip to Main Content

I have a script located in my nodejs application that needs to be run at specific time intervals to update some values in the database. I use node-cron library to successfully schedule this script to run locally but I haven’t been able to find a suitable way to get this script to run at the specified time intervals when the nodejs application is deployed to Azure. Any help resolving this would be appreciated.

2

Answers


  1. You can use Azure Functions with a timer trigger, Azure App Service background tasks, Azure Container Instances to achieve the same result in Azure. There are several other ways to do that, but they would be more complicated to setup and maintain.

    I’d probably go for Azure Function and a timer trigger.

    Login or Signup to reply.
  2. I do agree with @4c74356b41 that we can use azure timer trigger functions for it and I followed Microsoft-Document:

    @FunctionName("Func1")
    public void Func1(
      @TimerTrigger(name = "Func1Trigger", schedule = "0 */5 * * * *") String timerInfo,
          ExecutionContext ctx
     ) {
         // your code
         ctx.getLogger().info("Timer is triggered: " + timerInfo);
    }
    

    After changing then code then you can Publish it to Azure Functions in Portal and then you can run it in cloud.

    Alternatively you can use Logic apps for executing code in regular intervals of time :

    In logic apps you can use recurrence trigger:

    enter image description here

    Then in next step you can call your function app to run it.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search