public async Task <bool> CheckTargetInstanceRunningStatus(string serviceName, string currentZone, string serviceId, MasterOrSlaver masterOrSlaver) { var queryResult = await _consul.Health.Service(serviceName, currentZone, false); var tarService = queryResult.Response.Where(serviceEntry => serviceEntry.Service != null && serviceEntry.Service.ID == serviceId && serviceEntry.Service.Tags.Contains(masterOrSlaver.ToString())).FirstOrDefault(); return(tarService?.Checks.Where(serviceCheck => !string.IsNullOrWhiteSpace(serviceCheck.ServiceID)).FirstOrDefault()?.Status == HealthStatus.Passing ? true : false); }
/// <summary> /// 获取指定服务状态 /// </summary> /// <param name="serviceName">服务名</param> /// <param name="currentZone">分片键</param> /// <param name="masterOrSlaver">主从身份</param> /// <returns></returns> public async Task <CurrentServiceStatus> GetCurrentServiceStatus(string serviceName, string currentZone, MasterOrSlaver masterOrSlaver) { var queryResult = await _consul.Health.Service(serviceName, currentZone, false); var tarService = queryResult.Response.Where(serviceEntry => serviceEntry.Service != null && serviceEntry.Service.Tags.Contains(masterOrSlaver.ToString())).FirstOrDefault(); CurrentServiceStatus status = CurrentServiceStatus.Unsetting; if (tarService != null && tarService.Checks.Any(serviceCheck => !string.IsNullOrWhiteSpace(serviceCheck.ServiceID))) { var serviceStatus = tarService.Checks.Where(serviceCheck => !string.IsNullOrWhiteSpace(serviceCheck.ServiceID)).FirstOrDefault(); if (serviceStatus != null) { status = serviceStatus.Status == HealthStatus.Passing ? CurrentServiceStatus.Running : CurrentServiceStatus.Critical; } } return(status); }