Posts

Showing posts from January, 2017

Use the IBinder! #webjobs rock

What if you don't want to mess around with your Azure Storage Account and bother with  creating a Blob Client in your web job, but just want to be ... taken care of (as Web Jobs are so great at doing)? Well, as it turns out, it's really easy to get a hold of a Blob inside your WebJob method - just use the IBinder! Let's read some JSON data, as an example: public static async Task HandleMessage( ... , IBinder binder) {   ...   var json =     await  binder.BindAsync (       new BlobAttribute($"{blobContainer}/{blobName}"));   var obj = JToken.ReadFrom(new JsonTextReader(json));   ... } You can also bind to TextWriter , CloudBlockBlob , string (for reading), Stream and more !  If you know up-front which blob you want to read, bind to it directly in your method declaration . That's it! Web Jobs rock!

Function had errors. See Azure WebJobs SDK dashboard for details. Instance id is ...

Image
When your Azure WebJobs suddenly starts misbehaving, it might feel good to know that the reason for the failure is spelled out for you ... just not where you might expect it, say in your debugger console window: Super helpful, thanks. To easily get a hold of the issue, hook up your Azure Storage Explorer to your WebJobs storage account, browse your azure-webjobs-hosts blob container and then check through the output-logs . There, if you sort them by Last Modified  you'll quickly find the entry of interest: Downloading your file and opening it in a text editor, you should have a better chance finding the root cause of your issue. Did I miss an existing and useful feature in the SDK dashboard that relates to this? If so, please let me know in the comments!

Blob identifiers must be in the format 'container/blob'. #webjobs rocks.

... Or binding to a blob that your web job method wants to generate. As we've learned with WebJobs, the payload processed by our QueueTriggers work in tandem with our other bindings . Now, what if we want to bind to a blob that doesn't yet exist and that the requester couldn't possibly know about? As it turns out, we can add custom data to our payload object and use that data in our binding:         public class JobDescription         {             public string BlobPath { get; set; }             public string ProjectId { get; set; }             public string Method { get; set; }             public string GeneratedBlobId { get; set; } = Guid.NewGuid().ToString("n");         } The GeneratedBlobId above, is nothing that we expect the client to send in, but instead generate as the binding engine instantiate our JobDescription object to perform its magic (as a matter fact, I tend to declare my WebJob input classes as a part of the static cla