Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I invoke an Azure webjob from an Azure website and pass it parameters?

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.

like image 500
LeeKay Avatar asked Mar 08 '14 05:03

LeeKay


3 Answers

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

like image 180
Cristian Avatar answered Oct 13 '22 19:10

Cristian


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.

like image 8
Amit Apple Avatar answered Oct 13 '22 18:10

Amit Apple


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>

like image 4
Florin D Avatar answered Oct 13 '22 17:10

Florin D