Reputation: 17560
Im creating a worker role that i would like to know, within my SQL data layer, if its running.
I register the role when onStart
is called and I am considering to unregister it in the onStop
method. Can i count on onStop
is being called? or should i make it report its alive every 10min and have another application check that its live and if not, set the unit as offline?
How would people get around this problem about distributed programs?
Is it possible to get a Unique Guid for a specific instance of a worker/web role.
Upvotes: 1
Views: 127
Reputation: 170549
No, you can't count on OnStop()
being called. If the node where your instance runs crashes OnStop()
is not called. If an exception is propagated outside Run()
or OnStart()
of your instance OnStop()
is not called. Those are the top cases I can think of right now, perhaps there're more of them. The bottom line is you can't count on OnStop()
being called.
You should use heartbeats stored in some persistent storage - like SQL Azure or Azure Queues or whatever else. When you want to do "cleanup" or "reprocessing" you just select stuff that has no heartbeats for some reasonably long period of time. For example, live entities will issue heartbeats every one minute, then you can consider anything that had no heartbeats for five minutes or more dead.
Upvotes: 1
Reputation: 60153
A heartbeat is the right way to do this. You can't guarantee that OnStop
will be called, because hardware can fail suddenly.
Upvotes: 1