Is the Windows Azure operating system restarting or reseting a running worker role automatically from time to time? Or can I rely on the fact that my Worker role is running infinitely if I have a loop in the Run() method?
Role instances (whether Worker or Web) are recycled at least once monthly, as the Guest OS is updated on a monthly basis. The Host OS is refreshed on a quarterly basis, potentially resulting in additional role recycles (assuming Host and Guest updates are performed separately).
Having said that: You can choose to not be auto-updated to the latest Guest OS, by specifying a Guest OS version to use. You cannot opt out of Host OS updates.
In general, you should not rely on a role instance running infinitely. You need to assume there will be reboots in your future. Aside from Host OS updates, there are hardware failures that can and will occur.
See here for more information about Guest OS updates, and here for Host OS updates.
In no event can you rely on the host machine running continuously - it will be sometimes stopped for updates and it can crash for whatever reason. So your code should be aware and set checkpoints periodically and be able to resume.
So yes, you can have a while( true ) doStuff()
loop, but you have to design your code so that its operations that affect global storage - SQL Azure, blobs, queues and tables - leaves that storage in consistent state at all times. This way should your loop be interrupted (by a crash or by an exception for aborting the thread it is running on) your code can resume once the role is restarted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With