Exemplo n.º 1
0
        public async Task <ExecutionStatus> UnregisterService()
        {
            ExecutionStatus status;

            if (_consulServiceInstance == null)
            {
                status         = ExecutionStatus.Bad();
                status.Message = $"No service is registered";
                return(status);
            }
            _canRun = false;

            try
            {
                var result = await _client.Agent.ServiceDeregister(_consulServiceInstance?.Id);

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    status         = ExecutionStatus.Good();
                    status.Message = $"Service with id {_consulServiceInstance.Id} was successfully unregistred.";
                }
                else
                {
                    status         = ExecutionStatus.Bad();
                    status.Message = $"There were some problems unregistering service with id {_consulServiceInstance.Id}.";
                }
            }
            catch
            {
                status         = ExecutionStatus.Bad();
                status.Message = $"There were some problems unregistering service.";
            }

            return(status);
        }