sharptooth
sharptooth

Reputation: 170499

Can I be sure that once Azure role Stopping has been raised the role is never rerun in the same process?

Azure role have RoleEnvironment.Stopping event that is raised when the role is being stopped. I discovered some issue in some unrelated code that needs special treatment in cases when the role is being stopped. Something like:

public class SomeFarAwayClass {
  void someFarAwayFunction()
     if( roleIsBeingStopped ) {
         workSpecially();
     } else {
        workUsually();
     }
  }
}

Now I want to subscribe to RoleEnvironment.Stopping and in the event handler raise the roleIsBeingStopped permanently. Something like this:

public class SomeFarAwayClass {
  //
  private static bool roleIsBeingStopped = false;
  public void SetBeingStopped() { roleIsBeingStopped = true; }
}

class MyRoleClass : RoleEntryPoint {
    overribe bool OnStart()
    {
        RoleEnvironment.Stopping += stopping;
        return base.OnStart();
    }

    void stopping(object sender, RoleEnvironmentStoppingEventArgs args)
    {
        SomeFarAwayClass.SetBeingStopped();
    }
}

This solution implies that the role is never restarted in the same process, otherwise I'll need to reset the flag at some point. So far I've never seen Azure roles being restarted in the same process, it's a new process every time.

Can I be sure that once Azure role Stopping has been raised the role is never rerun in the same process?

Upvotes: 0

Views: 49

Answers (1)

Yossi Dahan
Yossi Dahan

Reputation: 5357

I think you probably can, but at the same time you don't need to, because you also have the OnStart call you could use to re-set the flag. I generally prefer to not rely on thing out of my control where I don't have to (of which there are many!), this would be one I'd avoid personally.

Upvotes: 1

Related Questions