My weekend code kata was something I was thinking since last year: run AjSharp in Azure Worker Roles. The idea is: a worker role instance can receives text via queue messages containing AjSharp code, and execute it. The output is send as a message to other queue.
The result was committed in my AjCodeKata project: you must download trunk\Azure\AzureAjSharp AND trunk\AjLanguage (where AjSharp projects reside).
AzureAjSharp.WorkerRole: sample worker role, with these lines added:
CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); Processor processor = new Processor(account); processor.Start();
Azure.AjSharp: the class library. It contains Processor class. The constructors need a cloud account and the names of: requests queue, responses queue and blob container. The request queue has messages with AjSharp code to execute. Response queue has the output text of such executions. The above processor.Start() command initiates the read and process of AjSharp code.
AzureAjSharp.Console: it reads lines from console, and when it reads a “send” line, the text is converted to a cloud message, sending it to the request queue. It has a thread that reads the response queue and prints the results.
AzureLibrary: auxiliar classes.
AjSharpVS2010, AjLanguageVS2010: AjSharp implementation.
When I run the console application, I can send AjSharp code to worker roles:
And more: AjSharp supports Include(“filetobeincluded”); where the file contains AjSharp code. I modified the launch of AjSharp machine to have an Include subroutine implementation that reads the content from a blob container.
Then, I uploaded some simple code (the files are in Examples folder in Azure.AjSharp project) to ajsfiles blob container (DevStorage in this test):
This is the test running (using Include) HelloWorld.ajs, and ForOneToTen.ajs:
– Write more utilities in AjSharp, to be included if they are needed: file and directory utilities, download and upload of blobs, send and receive message using queues, broadcast messages to all worker instances, download and load of assemblies, etc. Sky is the limit! 😉
Then, you (or your program) can dinamically send tasks and receive results. Nice to have: Guids to identify tasks and their results; web interface; results stored as blob texts; cache (and flush) of included blob files, etc…
Angel “Java” Lopez