13

I have an Azure webjob that I want to invoke from an Azure website. I want to pass string parameters from the website to the webjob.

I know I can invoke the webjob as a REST API (https://github.com/projectkudu/kudu/wiki/Web-jobs).
So I can invoke the webjob without any parameters: POST jobs/triggered/myjobname/run

But adding parameters at the end doesn't appear to be working, i.e. jobs/triggered/myjobname/run?myparam1=value1

The information I see on using attributes in Microsoft.WindowsAzure.Jobs for binding doesn't mention my case, just binding to Azure storage items (http://blogs.msdn.com/b/jmstall/archive/2014/01/28/trigger-bindings-and-route-parameters-in-azurejobs.aspx).

Is what I want to do doable? Do I need to do something like create a new item in an Azure storage queue to trigger my webjob?

Thanks.

4

4 回答 4

12

您可以使用以下地址调用带有参数的 azure webjob:“ https://mywebsite.scm.azurewebsites.net/api/triggeredwebjobs/mywebjob/run?arguments=myparameter

class Program
{
    static void Main(string[] args)
    { 
        if (args[0]=="myparameter")
        ... 
    }
}

一些信息:https ://github.com/projectkudu/kudu/pull/1183

于 2015-07-15T19:51:05.443 回答
8

如果您想从您的网站调用 WebJob,您可以做的最好的事情就是在您的网站中包含 WebJob 代码并简单地调用该代码,您仍然可以轻松地从您的网站内部使用 WebJob SDK。(用于调用 WebJobs SDK 方法示例:https ://web.archive.org/web/20180415074357/http://thenextdoorgeek.com/post/WAWS-WebJob-to-upload-FREB-files-to-Azure-Storage -使用-the-WebJobs-SDK)。

您不想从您的网站调用 WebJob 的原因是该调用包含您不想存储在您的网站上的秘密(部署凭据)。

如果您宁愿将 WebJob 和网站代码分开,最好的做法是使用队列进行通信,WebJob 侦听队列,网站将请求推送到队列。

关于原始问题,目前没有办法将参数传递给 WebJob 调用调用。

于 2014-03-08T19:29:55.180 回答
4

我花了一段时间才弄清楚如何使用 Azure Portal UI(而不是 Post Api/Kudu)设置带有参数的作业,所以这里是步骤:

  1. 在您的 WebApp 上创建 Webjob

  2. 在“Scheduler Job Collections”、“Scheduler Job”列表中的区域集合之一中找到 Web Job

  3. 在“操作设置”中为您的工作更改 URL 并将其附加 ?arguments=<myArgument>到它,使其最终看起来像:

    ...scm.azurewebsites.net/api/triggeredwebjobs/<my-job-name>/run?arguments=<myArgument>

于 2016-06-17T14:47:16.707 回答
2

记录在案的方法是将一个或多个 Azure 队列消息放入队列中。每条消息都应包含足够的参数信息,以让您的网络作业发挥作用。

在您的 WebJob 中使用 QueueTriggerAttribute 以允许 Azure 在收到适当的队列消息时自动启动 WebJob。

详情在这里

http://azure.microsoft.com/en-gb/documentation/articles/websites-dotnet-webjobs-sdk-storage-queues-how-to/

于 2015-01-28T08:23:24.100 回答