Question

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.

Était-ce utile?

La solution

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/

Autres conseils

Have you tried a service bus based approach? push the task to be completed into a topic. The instance can create a subscription named based of the instance number. (which you can get out of the RoleEnvironment.CurrentInstance.Id). In this way, even if the instance goes down, the message will still be delivered to the subscription for the instance to grab after it comes back up.

The subscriptions could also be filtered subscriptions based on data on the message.

Either way a simple queueing mechanism might line up more semantically with what you are trying to do.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top