private void OnGracefulShutdownRequest(GracefulShutdownRequest request) { try { _log.Log(LogCatagory.Info, "ServiceBoot recieved request from {0} to gracefully shutdown service. Reason: {1}", request.Sender, request.Reason); _log.Log(LogCatagory.Info, "Stopping Windows service instance..."); if (Environment.UserInteractive) { _serviceInstance.StopInstance(); } else { var service = _serviceInstance as ServiceBase; if (service == null) { _log.Log(LogCatagory.Warn, String.Format("Could not cast service instnace to type of ServiceBase. Instance: {0}.", _serviceInstance)); } service.Stop(); } _log.Log(LogCatagory.Info, "Completed graceful shutdown of service."); } catch (Exception e) { _log.Log(LogCatagory.Error, e, "ServiceBoot caught an unexpected exception while attempting to gracefully shutdown services."); } }
private void HandleGracefulShutdownRequest(GracefulShutdownRequest request) { if (!_gracefullShutdownInProgress.Contains(request.ShardRegion)) { if (_currentState.Regions.TryGetValue(request.ShardRegion, out var shards)) { Log.Debug("Graceful shutdown of region [{0}] with shards [{1}]", request.ShardRegion, string.Join(", ", shards)); _gracefullShutdownInProgress = _gracefullShutdownInProgress.Add(request.ShardRegion); ContinueRebalance(shards.ToImmutableHashSet()); } } }