Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure WebJobs - Can I use Async Methods?

Tags:

I was wondering if the Azure WebJobs SDK can trigger async methods? Currently I have a method that looks like the following:

class Program {     static void Main(string[] args)     {         var host = new JobHost();         host.RunAndBlock();     }      public static void ProcessStuff([QueueInput("myqueue")] string msg)     {         var tsk = ProcessStuffAsync(msg)                   .ContinueWith(x => HandleAsyncError(x),                       TaskContinuationOptions.OnlyOnFaulted);         tsk.Wait();     }      public static async Task ProcessStuffAsync(string msg)     {         // do some async stuff and await it     }      // other methods ... } 

However, I was wondering if I could just have the JobHost know to call my async method instead? There's not a ton of documentation out there on trying to use async/await in WebJobs, and it would be really nice if I could.

I'm trying to run this locally to test ... but the WebJobs SDK doesn't support the local Storage Emulator...

UPDATE 4/7/2014: Victor's answer is correct, but I did want to show what you'll see from using async methods in a WebJob (they do work).

For a method in your WebJob that looks like the following:

public async static Task ProcessMessageAsync([QueueInput("testq2")] string message) {     await Task.Delay(50);      Console.WriteLine("Processing Message Async...");     Console.WriteLine(message); } 

You will see the following output in your WebJobs log:

running in pid: 6272 Timestamp:4:36:02 PM Parameters bound. Invoking user function. -------- Warning: This asynchronous method will be run synchronously. Processing Message Async... a test message -------- Success 
like image 786
ericb Avatar asked Apr 07 '14 15:04

ericb


People also ask

Which of the following is not true about WebJobs?

Explanation : A. Incorrect: WebJobs can be triggered by both queue messages and blobs.

What is the use of WebJobs in Azure?

WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs. You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks.

What is azure WebJobs hosts?

azure-jobs-host-output container is the key for troubleshooting web jobs. This container hosts logs created by the WebJob runtime during initialization and termination of every execution.


1 Answers

Async is now supported. See the blog post here.

Unfortunately, the short answer to both questions is: not supported.

(slightly) longer answer:

WebJobs SDK does not support async methods. If you look in the execution log (on the dashboard) you will see a warning saying that async functions (functions that return Task or Task<>) are executed synchronously.

We don't support the local emulator. You have to use a real Storage Account when developing.

like image 195
Victor Hurdugaci Avatar answered Sep 20 '22 12:09

Victor Hurdugaci