public string Schedule => "0 * * * *"; // at the start of each hour public async Task ExecuteAsync(CancellationToken cancellationToken) { // Clear branch holidays info cache branchHolidays = null; var checkStart = DateTime.UtcNow; var pendingSubscriptions = await subscriptionService.GetPendingSubscriptions(checkStart, EventType.MissDailyReport); foreach (var subscription in pendingSubscriptions) { cancellationToken.ThrowIfCancellationRequested(); try { var user = subscription.User; DateTime userCurrentDate = TimeZoneInfo.ConvertTimeFromUtc(checkStart, TimeZoneInfo.FindSystemTimeZoneById(user.TimeZoneCode)); // Do not notify user if notification time has not passed yet if (userCurrentDate.Hour < subscription.CheckTime) { continue; } var shouldSubmitDailyReport = await ShouldSubmitDailyReport(user, userCurrentDate); cancellationToken.ThrowIfCancellationRequested(); if (shouldSubmitDailyReport && !await crmService.DailyReportExists(user.Chat.ChatId, userCurrentDate)) { telemetry.TrackEvent("Missing Daily Report Notification"); await telegramBot.NotifyMissedDailyReportAsync(user.Chat.ChatId); } subscription.LastCheck = checkStart; await subscriptionService.UpdateSubscription(subscription); } catch (Exception ex) { telemetry.TrackException(ex); } } }