我在使用 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();
}
}
下面是Function类代码:
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 Web 作业的正确方法。我这里缺少任何设置吗?
请指导。
最佳答案
确实有一些需要注意的地方:
- 部署 WebJob 时,请确保 WebJob 运行模式为“按需运行”。
- 删除main方法中的
RunAndBlock()
,否则它会不停地运行,这是为了连续的WebJob。 - 当您请求WEBHOOK时,请确保设置正确的授权,您可以在WebJob属性页面中获取webhook以及名称、密码。这是 Postman 页面。
然后您将能够从 WEBHOOK 运行 webjob。
关于azure - 通过 Webhook url 触发 Azure Web 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55339362/