How to make azure webjob run continuously and call the public static function without automatic trigger How to make azure webjob run continuously and call the public static function without automatic trigger azure azure

How to make azure webjob run continuously and call the public static function without automatic trigger


These steps will get you to what you want:

  1. Change your method to async
  2. await the sleep
  3. use host.CallAsync() instead of host.Call()

I converted your code to reflect the steps below.

static void Main(){    var host = new JobHost();    host.CallAsync(typeof(Functions).GetMethod("ProcessMethod"));    // The following code ensures that the WebJob will be running continuously    host.RunAndBlock();}[NoAutomaticTriggerAttribute]public static async Task ProcessMethod(TextWriter log){    while (true)    {        try        {            log.WriteLine("There are {0} pending requests", pendings.Count);        }        catch (Exception ex)        {            log.WriteLine("Error occurred in processing pending altapay requests. Error : {0}", ex.Message);        }        await Task.Delay(TimeSpan.FromMinutes(3));    }}


Use the Microsoft.Azure.WebJobs.Extensions.Timers, see https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/ExtensionsSample/Samples/TimerSamples.cs to create a trigger that uses a TimeSpan or Crontab instruction to fire the method.

Add Microsoft.Azure.WebJobs.Extensions.Timers from NuGet to your project.

public static void ProcessMethod(TextWriter log)

becomes

public static void ProcessMethod([TimerTrigger("00:05:00",RunOnStartup = true)] TimerInfo timerInfo, TextWriter log) 

for five minute triggers (using TimeSpan string)

You will need ensure your Program.cs Main sets up the config to use timers as follows:

static void Main()    {        JobHostConfiguration config = new JobHostConfiguration();        config.UseTimers();        var host = new JobHost(config);        // The following code ensures that the WebJob will be running continuously        host.RunAndBlock();    }