Exemple #1
0
        public async Task ProcessAsync(ServiceWatchItem item)
        {
            while (true)
            {
                try
                {
                    Logger?.LogTrace("{0} - Watching '{1}' for '{2}' environment", DateTime.Now, item.ServiceName, item.Environment);

                    var watchResponse = await Watcher.WatchAsync(new WatcherParameter(item.ToDictionary()));

                    if (watchResponse.Success)
                    {
                        Logger?.LogInformation(" Success watch for '{0}' in '{1}' environment", item.ServiceName, item.Environment);
                    }
                    else
                    {
                        Logger?.LogError(" Failed watch for '{0}' in '{1}' environment", item.ServiceName, item.Environment);
                    }

                    var serviceStatusLog = new ServiceStatusLogRequest
                    {
                        ServiceID            = item.ServiceID,
                        ServiceEnvironmentID = item.ServiceEnvironmentID,
                        Target     = item.ServiceName,
                        ActionName = Watcher.ActionName,
                        Success    = watchResponse.Success,
                        Message    = watchResponse.Message,
                        StackTrace = watchResponse.StackTrace
                    };

                    try
                    {
                        await Client.PostServiceEnvironmentStatusLog(serviceStatusLog);
                    }
                    catch (Exception ex)
                    {
                        Logger?.LogCritical(" Error on saving watch response ({0}): '{1}'", item.ServiceName, ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    Logger?.LogCritical(" Error watching service: '{0}': '{1}'", item.ServiceName, ex.Message);
                }

                Thread.Sleep(item.Interval ?? AppSettings.DelayTime);
            }
        }
Exemple #2
0
        public async Task ProcessAsync(ServiceWatchItem item)
        {
            while (true)
            {
                try
                {
                    Logger.LogTrace("{0} - Watching '{1}' for '{2}' environment", DateTime.Now, item.ServiceName, item.Environment);

                    var watchResponse = await Watcher.WatchAsync(new WatcherParameter { Values = item.ToDictionary() });

                    var watchLog = new ServiceStatusLog
                    {
                        ServiceID            = item.ServiceID,
                        ServiceEnvironmentID = item.ServiceEnvironmentID,
                        Target     = item.ServiceName,
                        ActionName = Watcher.ActionName,
                        Success    = watchResponse.Success,
                        Message    = watchResponse.Message,
                        StackTrace = watchResponse.StackTrace
                    };

                    try
                    {
                        await RestClient.PostJsonAsync(AppSettings.ServiceStatusLogUrl, watchLog);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(" Error on saving watch response ({0}): '{1}'", item.ServiceName, ex);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(" Error on watch: '{0}'", ex);
                }

                Thread.Sleep(item.Interval.HasValue ? item.Interval.Value : AppSettings.DelayTime);
            }
        }