Building off of this question/answer on StackOverflow, I'm looking to make a single Azure instance run certain code at one time rather than have every instance run the code.
However, what I can't seem to find is how to determine if roles that are still in RoleEnvironment.CurrentRoleInstance.Role.Instances
are busy and/or healing. I would need this to hand over control over running my code to another instance if one is failing.
RoleInstance
doesn't seem to have any properties to determine current role status.
Might I suggest a different take, rather then use a complex topology based selection, instead implement a simple 'traffic cop' pattern. In a nutshell, this uses a temporary blob lease to ensure that only one instance (the one that gets the lock) can perform the singleton operation. If the instance that was doing the action becomes unresponsive, the lease will fail to be renewed and another instance can quickly take over processing.
I have some sample code and a write-up on my blog at: http://brentdacodemonkey.wordpress.com/2012/07/27/the-traffic-cop-pattern/