Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Role Start Order

Is it possible to define the order in which Azure roles should start?

I have a cache worker role which I'm obviously using for cache. I'm also using it as my session state provider.

When I start my solution in visual studio and it opens in a browser I get an error message saying the cache doesn't exist. If I make another request it works fine. This seems to be because the web role starts a fraction before the cache role it is trying to use.

It isn't really an issue in a live environment because Azure wont route requests to the application until all of the roles are ready however it's a bit annoying when I'm running locally.

Thanks

like image 204
radm4 Avatar asked Nov 20 '25 04:11

radm4


1 Answers

You can't specify role startup order. You can, however, keep your web role instances out of the load balancer until you determine the environment is up and running sufficiently.

In your OnStart(), you could put some code that tries getting something from the cache (which will likely fail if the web role instance comes up prior to the cache role). Or maybe ping the cache role instances (I'll leave that up to you, to determine best way of seeing that the cache role instances are up). Just keep retrying periodically until you have success, then return from OnStart(). At this point, the load balancer will start directing traffic to the role instances, and you should be in good shape.

Note: While your web role instances are unavailable, you'll see an http error since the site will be temporarily unavailable during startup, but you shouldn't see the cache error message.

More details around OnStart: here.

like image 190
David Makogon Avatar answered Nov 22 '25 19:11

David Makogon