private void SendReadyReminders(object state) { //ищем записи var readyReminders = _storage.Get(ReminderItemStatus.Ready); foreach (var readyReminder in readyReminders) { try { SendReminder(readyReminder); _storage.Update(readyReminder.Id, ReminderItemStatus.Sent); SendingSucceeded?.Invoke(this, new SendingSucceeededEventArgs { SendingItem = readyReminder }); } catch (Exception e) { _storage.Update(readyReminder.Id, ReminderItemStatus.Failed); SendingFailed?.Invoke( this, new SendingFailedEventArgs { SendingItem = readyReminder, SendingException = e }); } } //отправляем //Если ок то в статус send, иначе failed }
public void CheckAwaitingReminders(object dummy) { var ids = _storage .Get(ReminderItemStatus.Awaiting) .Where(r => r.IsTimeToSend) .Select(r => r.Id); _storage.UpdateStatus(ids, ReminderItemStatus.Ready); }
public IActionResult Get(Guid id) { ReminderItem reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } return(Ok(new ReminderItemGetModel(reminderItem))); }
private void CheckAwaitingReminders(object state) { var awaitingReminders = _storage.Get(ReminderItemStatus.Awaiting); foreach (var awaitingReminder in awaitingReminders) { if (awaitingReminder.IsReadyToSend) { _storage.Update(awaitingReminder.Id, ReminderItemStatus.Ready); } } }
public IActionResult Get(Guid id) { var reminderItem = _reminderStorage.Get(id); if (reminderItem == null) { return(BadRequest(ModelState)); } return(Ok(new ReminderItemGetModel(reminderItem))); }
public IActionResult Get(Guid id) { _logger.LogInformation($"{nameof(Get)} called"); var reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } var model = new ReminderItemGetModel(reminderItem); return(Ok(model)); }
private void CheckAwaitingReminders(object dummy) { var ids = _storage .Get(ReminderItemStatus.Awaiting) .Where(r => r.IsTimeToSend) .Select(r => r.Id) .ToList(); if (ids.Count > 0) { _storage.UpdateStatus( ids, ReminderItemStatus.Ready); } }
private void SendReadyReminders(object state) { // find ready reminders // try "send" // if success update status to Sent // else update status to Failed var readyReminders = _storage.Get(ReminderItemStatus.Ready); foreach (var readyReminder in readyReminders) { try { // try "send" SendReminder(readyReminder); // update status to Sent _storage.Update( readyReminder.Id, ReminderItemStatus.Sent); // send event SendingSucceeded?.Invoke( this, new SendingSucceededEventArgs { SendingItem = readyReminder }); } catch (Exception e) { // update status to Failed _storage.Update( readyReminder.Id, ReminderItemStatus.Failed); // send event SendingFailed?.Invoke( this, new SendingFailedEventArgs { SendingItem = readyReminder, SendingException = e }); } } }
private void SendReadyReminders(object state) { //отправка //находим что отправлять //отправляем //если ок то статус в set //инача статус в failed var readyReminders = _storage.Get(ReminderItemStatus.Ready); foreach (var readyReminder in readyReminders) { try { //отправляем, используем делегат SendReminder(readyReminder); //статус в sent _storage.Update( readyReminder.Id, ReminderItemStatus.Sent); //запускаем событие об успешной отправке SendingSuccedded?.Invoke( this, new SendingSucceededEventArgs { SendingItem = readyReminder }); } catch (Exception e) { //статус в fault _storage.Update( readyReminder.Id, ReminderItemStatus.Failed); //запускаем событие о сбое отправки SendingFailed?.Invoke( this, new SendingFailedEventArgs { SendingItem = readyReminder, SendingException = e }); } } }
public IActionResult Get(Guid id) { //if (id == default(Guid)) //{ // ModelState.AddModelError("id", "ID должен быть GUID"); // return BadRequest(ModelState); //} ReminderItem reminderItem = _reminderStorage.Get(id); if (reminderItem == null) { return(NotFound()); } return(Ok(new ReminderItemGetModel(reminderItem))); }
public void CheckAwaitingReminders() { var ids = storage.Get(ReminderStatus.Awaiting, 0, 0).Where(r => r.IsTimeToAlarm).Select(r => r.Id); storage.UpdateStatus(ids, ReminderStatus.ReadyToSend); }