Question

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.

Was it helpful?

Solution 2

If you want to invoke a WebJob from your Website, the best thing you can do is simply have the WebJob code inside your Website and simply call that code, you can still easily use the WebJob SDK from inside your Website. (for calling a WebJobs SDK method sample: https://web.archive.org/web/20180415074357/http://thenextdoorgeek.com/post/WAWS-WebJob-to-upload-FREB-files-to-Azure-Storage-using-the-WebJobs-SDK).

The reason you wouldn't want to invoke the WebJob from your Website is that the invocation contains a secret you rather not store on your Website (deployment credentials).

If you rather separate WebJob and Website code, the best thing to do is to communicate using a queue, the WebJob listens on the queue and the Website pushes the request to the queue.

Regarding the original question, currently there is no way to pass parameters to the WebJob invoke call.

OTHER TIPS

You can invoke an azure webjob with parameters using the address: "https://mywebsite.scm.azurewebsites.net/api/triggeredwebjobs/mywebjob/run?arguments=myparameter"

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

Some info in: https://github.com/projectkudu/kudu/pull/1183

Took me a while to figure out how to setup the job with arguments using Azure Portal UI (not Post Api/Kudu), so here are the steps:

  1. Create the Webjob on your WebApp

  2. Locate the Web Job in one of the regional collections in the "Scheduler Job Collections", "Scheduler Job" lists

  3. Change the Url in the "Action settings" for your job and append the ?arguments=<myArgument> to it so it ends up looking like:

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

The documented way of doing this is to put one or more Azure Queue Messages into a Queue. Each message should contain enough parameter information to allow your webjob to do it's magic.

Within your WebJob use a QueueTriggerAttribute to allow Azure to automatically start the WebJob up when the appropriate queue message is received.

Details here

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top