通过 Webhook 触发 Azure Web 作业 url

Trigger Azure Web Jobs through Webhook url

我在使用 Webhook url 触发 Azure webjobs 时遇到问题。

我创建了一个简单的'NoAutomaticTriggerAttribute' Azure web 作业下面是代码

例如:

 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();
    }
}

下面是函数 class 代码:

 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.");
    }
}

现在当我尝试使用 webhook 调用 webjob 时 url :

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

它给出了这样的回应:

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

AzureWebJobsDashboard 中未捕获任何详细信息

请告诉我按需调用 Azure webjobs 的正确方法。这里有没有我遗漏的设置。

请指导。

确实有几点需要注意:

  1. 部署 WebJob 时,请确保您的 WebJob 运行 模式为 运行 按需。

  1. 删除main方法中的RunAndBlock(),否则会运行不停,这是为了连续的WebJob。
  2. 当您请求WEBHOOK时,确保设置正确的授权,您可以在WebJob属性页面中获取webhook和名称、密码。这是 Postman 页面。

然后您就可以从 WEBHOOK 运行 网络作业了。