While still in development the Azure WebJob SDK offers some cool features for procession and supply of information. A good example is the sample that observes the Azure Queue and processes an item as soon as it spots one.
Scenario: time-controlled activities – without queue and so on
My scenario was quite simple. I was searching for a way to open a method time-controlled and store the data in the blob storage – without a cloud.
The code:
1: class Program 2: { 3: static void Main(string[] args) 4: { 5: JobHost host = new JobHost(); 6: host.Call(typeof(Program).GetMethod("WriteFile")); 7: } 8: 9: [NoAutomaticTrigger] 10: public static void WriteFile([Blob("container/foobar.txt")]TextWriter writer) 11: { 12: writer.WriteLine("Hello World..." + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString()); 13: } 14: }
If you have a look on the most popular examples you might recognize that the method “RunAndBlock” won’t be started. That is also not necessary since the program will be “woken” by the scheduler to open the “write” method.
To get the code to work you have to deposit the following configurations. Afterwards you are able to zip the whole console application and upload it into the Azure portal and configure the scheduler.
Configurations:
1: <?xml version="1.0" encoding="utf-8" ?> 2: <configuration> 3: <connectionStrings> 4: <add name="AzureJobsDashboard" connectionString="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=..."/> 5: <add name="AzureJobsStorage" connectionString="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=..."/> 6: </connectionStrings> 7: <startup> 8: <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 9: </startup> 10: </configuration>
After the upload:
The “WebJobs” are living inside the Azure Website. If you require a constantly running WebJob you have to make sure that the Azure website runs with “AlwaysOn=True”!
There is also a small administration portal for the WebJobs:
On the storage side a container will be created – including the container I’m using n the console.
And of course the data is also available:
Result
The first steps seem easy but at the same time quite clever. I like that so far.
The (not to complicated) code is from a developer of the WebJob team on Stackoverflow. Of course it is also available on GitHub.