Andre Marc-Aurele
Andre Marc-Aurele

Reputation: 11

Get id or name of Azure Webjob run when triggered externally

when I start a webjob using the rest api : /api/triggeredwebjobs/{job name}/run?arguments={arguments}

I need to know if the program invoked ran successfully or not and for now I request the latest result from the history using .../api/triggeredwebjobs/{job name}/history

Now, is there a way to get the {id} of the Job just after I invoke ? Because obviously there's no way to be sure that the latest history is the job I just ran. Or is there another way to get things done?

Thanks.

Upvotes: 1

Views: 1992

Answers (3)

David Ebbo
David Ebbo

Reputation: 43203

We just added support for this in the WebJobs API. The way it works is that when you send the POST request to trigger the WebJob, you now get back a location attribute, with a URL to the details of the run that was started. e.g.

Location: https://mysite.scm.azurewebsites.net/api/triggeredwebjobs/SomeJob/history/201605192149381933

You can then query this URL to track the run, e.g.

{
  "id": "201605192149381933",
  "name": "201605192149381933",
  "status": "Success",
  "start_time": "2016-05-19T21:49:38.1933956Z",
  "end_time": "2016-05-19T21:49:39.4826458Z",
  "duration": "00:00:01.2892502",
  "output_url": "https://mysite.scm.azurewebsites.net/vfs/data/jobs/triggered/SomeJob/201605192149381933/output_log.txt",
  "error_url": null,
  "url": "https://mysite.scm.azurewebsites.net/api/triggeredwebjobs/SomeJob/history/201605192149381933",
  "job_name": "SomeJob",
  "trigger": "External - ARMClient/1.1.1.0"
}

Upvotes: 2

Julien
Julien

Reputation: 121

You can call this anywhere in your code and it works ! (Not in debug, but when published)

Console.Out.WriteLine("RUN NAME : " + Environment.GetEnvironmentVariable("WEBJOBS_RUN_ID"));

Upvotes: 2

mathewc
mathewc

Reputation: 13568

Yes, we added a new binder in the extensions library to allow you to get the instance ID - ExecutionContext. See an example here in the extensions repo samples. To use this binding you'll have to pull in the beta1 Microsoft.Azure.WebJobs.Extensions prerelease package, and add config.UseCore() to your startup code (as the sample app shows). This was added based on another ask similar to yours.

Upvotes: 2

Related Questions