private async Task ExecuteTimer(TimerToExecute timer, CancellationToken token) { if (token.IsCancellationRequested) { _runtime.PersistenceProvider.ClearTimerIgnore(timer.TimerId); return; } try { var timerToExecute = timer; await _runtime.ExecuteTimer(timerToExecute.ProcessId, timerToExecute.Name); } // After implementing logger insert log here catch (ImpossibleToSetStatusException) {} catch (ProcessNotFoundException) {} finally { _runtime.PersistenceProvider.ClearTimer(timer.TimerId); } }
private async Task ExecuteTimer(TimerToExecute timer, CancellationToken token) { if (token.IsCancellationRequested) { _runtime.PersistenceProvider.ClearTimerIgnore(timer.TimerId); return; } void LogException(Exception ex) { _runtime.LogError("Execute timer error", new Dictionary <string, string>() { { "Message", ex.Message }, { "StackTrace", ex.StackTrace }, { "ProcessId", timer.ProcessId.ToString("D") }, { "TimerId", timer.TimerId.ToString("D") }, { "TimerName", timer.Name }, }); } void LogExceptionOrThrow(Exception ex) { if (_runtime.Logger != null) { LogException(ex); } else { throw ex; } } void LogExceptionOrSuppress(Exception ex) { if (_runtime.Logger != null) { LogException(ex); } } try { var timerToExecute = timer; await _runtime.ExecuteTimerAsync(timerToExecute.ProcessId, timerToExecute.Name).ConfigureAwait(false); } // After implementing logger insert log here catch (ImpossibleToSetStatusException ex) { LogExceptionOrSuppress(ex); } catch (ProcessNotFoundException ex) { LogExceptionOrSuppress(ex); } catch (StatusNotDefinedException ex) { LogExceptionOrSuppress(ex); } catch (Exception ex) { LogExceptionOrThrow(ex); } finally { try { _runtime.PersistenceProvider.ClearTimer(timer.TimerId); } catch (Exception ex) { LogExceptionOrThrow(ex); } } }