【问题标题】:Trigger Azure Web Jobs through Webhook url通过 Webhook url 触发 Azure Web Jobs
【发布时间】:2019-03-25 13:51:15
【问题描述】:

我在使用 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();
    }
}

下面是函数类代码:

 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 url 调用 webjob 时:

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

它给出这个响应:

“没有为'/api/triggeredwebjobs/SampleWebJob2/run'注册路由”

AzureWebJobsDashboard 中没有捕获任何细节

如果它是按需调用 Azure webjobs 的正确方法,请告诉我。这里有没有我缺少的设置。

请指导。

【问题讨论】:

    标签: azure azure-webjobs


    【解决方案1】:

    确实有几点需要注意:

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

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

    然后您将能够从 WEBHOOK 运行网络作业。

    【讨论】:

    • 谢谢!这真的很有帮助。我还有一个问题。我只是想在不同的计划中使用不同的参数集运行相同的 Azure Web 作业。请让我知道我需要为此做的更改。
    • @user1941025,关于如何传递参数,您可以将 ?arguments={your arguments} 添加到 url 的末尾。 REST API 在这里描述:github.com/projectkudu/kudu/wiki/…
    • @user1941025,如果这对您有帮助,您可以将其标记为答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多