Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Azure Web Jobs through Webhook url

I have an issue in triggering Azure webjobs using Webhook url.

I created a simple 'NoAutomaticTriggerAttribute' Azure web job below is the code

For example:

 class Program
{
    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
        var test = ConfigurationManager.ConnectionStrings["AzureWebJobsDashboard"].ConnectionString.ToString();
        var config = new JobHostConfiguration(test);

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost(config);
        host.Call(typeof(Functions).GetMethod("ProcessMethod"));
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
}

Below is the Function class code:

 public class Functions
{
    // This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.

    [NoAutomaticTriggerAttribute]
    public static void ProcessMethod(TextWriter log)
    {
        log.WriteLine("This is First call from Main Method.");
    }
}

Now when i tried to call the webjob using the webhook url :

https://sample.scm.azurewebsites.net/api/triggeredwebjobs/SampleWebJob2/run

Its giving this response:

"No route registered for '/api/triggeredwebjobs/SampleWebJob2/run'"

There is no details captured in AzureWebJobsDashboard

Let me know if its the correct way to call the Azure webjobs on demand. Is there any setting that im missing here.

Please guide.

like image 487
user1941025 Avatar asked Mar 25 '19 13:03

user1941025


1 Answers

There are indeed some points to note:

  1. When you deploy your WebJob, make sure your WebJob run mode is Run on Demand.

enter image description here

  1. Delete RunAndBlock() in the main method or it will run without stop, it's for continuous WebJob.
  2. When you request the WEBHOOK make sure set the right authorization, you could get the webhook and the name, password in the WebJob properties page. Here is the Postman page.

enter image description here

enter image description here

Then you will be able to run the webjob from WEBHOOK.

enter image description here

like image 127
George Chen Avatar answered Oct 12 '22 13:10

George Chen