Ejemplo n.º 1
0
        private async Task ReportAsync()
        {
            while (!CancellationTokenSource.IsCancellationRequested)
            {
                Logger.LogInformation($"Job is announcing at {DateTime.UtcNow:h:mm:ss tt zz} ..." + QueueResults.Count());
                List <EndPointHealthResult> epResults = new List <EndPointHealthResult>();
                while (QueueResults.TryDequeue(out var endPointHealthResult))
                {
                    epResults.Add(endPointHealthResult);
                }

                if (epResults.Count > 0)
                {
                    await BroadCaster.BroadcastResultsAsync(epResults, this.DiscordWebHook, Logger, Settings.FamilyReporting);

                    if (Settings.StoreData)
                    {
                        CleanRedis();
                    }
                }
                else
                {
                    if (!isFirstRun)
                    {
                        await BroadCaster.BroadcastErrorAsync(this.DiscordWebHook, Logger);
                    }
                }

                TimeSpan delay;
                if (Settings.FixedTime)
                {
                    switch (Settings.TimeUnit)
                    {
                    case "day":
                        delay = (DateTime.Now.AddDays(1).Date - DateTime.Now);
                        break;

                    default:
                    case "hour":
                        delay = TimeSpan.FromMinutes(60 - DateTime.Now.Minute);
                        break;

                    case "minute":
                        delay = TimeSpan.FromSeconds(60 - DateTime.Now.Second);
                        break;
                    }
                }
                else
                {
                    delay = TimeSpan.FromMilliseconds(Settings.GetAnnouncementTimeIntervalInMs());
                }
                isFirstRun = false;
                await Task.Delay(delay);
            }
        }
Ejemplo n.º 2
0
        private async Task TrySendAlertAsync()
        {
            if (Settings.SendAlert)
            {
                if (QueueErrors.Count > 0)
                {
                    List <EndPointHealthResult> exceeded = new List <EndPointHealthResult>();
                    while (QueueErrors.TryDequeue(out var endPointHealthResult))
                    {
                        exceeded.Add(endPointHealthResult);
                    }

                    bool success = await BroadCaster.BroadcastAlertAsync(exceeded, DiscordWebHook, Logger);

                    if (success)
                    {
                        foreach (var e in exceeded)
                        {
                            QueueResults.Enqueue(e);
                        }
                    }
                }
            }
        }