问题
I have a set of stateless and stateful services in an app. Obviously I'd like them to run perfectly but there are instances where my app knows it cannot recover from a failure. For example, if it cannot load its configuration settings from KeyVault (and its failover copies), then there is no point going any further.
So question is, how to tell service fabric to give up the whole app? I have tried Partition.ReportFault(FaultType.Permenant) but bless it, it tries to start a new partition. :-)
Obviously we are sending alerts info to Ops and DevOps incl automated emails so they can recover but great if Service Fabric can accept a "suicide" request rather than generating (replica count x retry count) number of fatal error reports and eventually dying.
回答1:
What you want is to delete the service. That's a simple management operation that anyone with admin access to the cluster can do. A service can delete itself this way if you want it to commit suicide:
using (FabricClient fc = new FabricClient())
{
fc.ServiceManager.DeleteServiceAsync(this.Context.ServiceName);
}
Note that this requires the service to have admin access to cluster management operations. You might not want that if the service has Internet-facing endpoints (if someone manages to take advantage of a vulnerability in your service and take control of the process, you're hosed). In that case, it would be better to delegate the delete task to another service - an executioner, if you will - that has admin access, is only accessible from inside the cluster, and can delete services that are dead in the water anyway.
来源:https://stackoverflow.com/questions/39563875/service-fabric-how-to-gracefully-fail-an-app