質問

Is it a good practice to Wait/Sleep inside the RoleEntryPoint.OnStart method of a webrole? We want to make sure our service is fully ready before we tell Azure that we are ready to service request.

役に立ちましたか?

解決

Yes you can wait for a while in the OnStart method to initialize services.

OnStart performs the initialization of your system. If you have a service that you need to setup and initialize before you enter running state of your role you need to initialize that in the OnStart before you exit that method.

The role environment will continue to calling the Run method of your RoleEntryPoint right after you exit OnStart. The exact time it takes to call the next method is unknown. This will also move your service from RoleInstanceStatus.Busy to RoleInstanceStatus.Ready at which time the role instance will begin to receive traffic.

As far as I know there is no initialization timeout for the role instances. (The OnStop method on the other hand, when your instance for what ever reason shuts down, does, for practical reasons, have a limited time to finish executing. Not sure but at one time I heard five or fifteen seconds.)

他のヒント

As far as I know, when inside the OnStart the role status would be at Busy, which means it reported to the Fabric Controller that it still in initialization phase. I don't think it's good or bad to sleep in OnStart, but you might need to consider the role start timeout.

I think the better idea would be put your waiting logic in Run with some flags, so that it cannot accept the request until you are ready.

The purporse of the OnStart method is to perform all the initialization within. So, after this function exits, your instance is supposed to be fully functional. In your case I think it is good to wait a little bit in OnStart. During that time the role will have "Busy" status and will not receive any incoming web requests but still can communicate with storage and database.

In our project we have OnStart downloading all the necessary data from Blob storage, unpacking and registering it. Then we check that role is healthy and only after that leave the OnStart method.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top