private async Task SendScheduledRemindersAsync() { var reminders = await _storage.FindAsync(ReminderItemFilter.CreatedAtNow()); foreach (var reminder in reminders) { reminder.MarkReady(); await _storage.UpdateAsync(reminder); try { await _sender.SendAsync(new ReminderNotification( reminder.DateTime, reminder.Message, reminder.ChatId ) ); await OnReminderSentAsync(reminder); } catch (ReminderSenderException) { await OnReminderFailedAsync(reminder); } } }
private async Task OnTickAsync() { _logger.LogDebug("Ticked timer"); foreach (var reminder in await _storage.FindByAsync(ReminderItemFilter.CreatedAtNow())) { _logger.LogInformation($"Mark reminder {reminder.Id:N} as ready"); reminder.MarkReady(); await _storage.UpdateAsync(reminder); try { _logger.LogInformation($"Sending reminder {reminder.Id:N}"); await _sender.SendAsync( new ReminderNotification( reminder.ContactId, reminder.Message, reminder.DateTime ) ); await OnReminderSentAsync(reminder); } catch (ReminderSenderException exception) { _logger.LogError(exception, "Exception occured while sending notification"); await OnReminderFailedAsync(reminder); } } }