Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            int    delay        = configuration.GetValue <int>(ConfigurationKeys.WORKER_SECONDS_DELAY);
            string uploaderPath = configuration[ConfigurationKeys.UPLOAD_REPORT_PATH];

            while (!stoppingToken.IsCancellationRequested)
            {
                logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                if (DateTime.Now.Hour == 23 && DateTime.Now.Minute == 30)
                {
                    await reporter.SendMailAsync(await reportBuilder.BuildDailyReportAsync());

                    await reporter.SendMailAsync(await reportBuilder.BuildDayComparisonReport());
                }

                if (Directory.Exists(uploaderPath) && Directory.EnumerateFileSystemEntries(uploaderPath).Any())
                {
                    await reporter.UploadReportFromDirectoryAsync(uploaderPath);
                }

                await Task.Delay(TimeSpan.FromSeconds(delay), stoppingToken);
            }
        }