public void Execute() { try { TargetTask.Execute(); } catch (Exception exception) { Log.InfoFormat("{0} caught exception {1}", Name, exception.Message); Log.Debug("Exception", exception); var handlerPair = _exceptionHandlers.Cast <KeyValuePair <Type, ITask>?>() .FirstOrDefault(p => p.Value.Key.IsInstanceOfType(exception)); if (handlerPair.HasValue) { var handlerPairValue = handlerPair.Value; Log.InfoFormat("{0} handler is {1}", handlerPairValue.Key.Name, handlerPairValue.Value?.Name ?? "none"); (handlerPairValue.Value as IExceptionHandlerTask)?.SetSource(TargetTask, exception); handlerPairValue.Value?.Execute(); } else { Log.Info("No handler, rethrowing"); throw; } } finally { FinallyTask?.Execute(); } }
public void Execute() { var success = false; var attemptIndex = 0; do { ++attemptIndex; try { if (attemptIndex > 1 && TargetFailedTask != null) { Log.DebugFormat("Executing failure response task {0}", TargetFailedTask.Name); TargetFailedTask.Execute(); } TargetTask.Execute(); success = true; } catch (TE exception) { Log.ErrorFormat("Attempt #{0} to execute {1} failed: {2}", attemptIndex, TargetTask.Name, exception.Message); Log.Debug("Exception", exception); if (attemptIndex >= RetryCount) { Log.ErrorFormat("Reached limit of {0} retries of {1}", RetryCount, TargetTask.Name); throw; } if (RetryDelayMilliseconds > 0) { Log.InfoFormat("Waiting {0} milliseconds before retrying", RetryDelayMilliseconds); Thread.Sleep(RetryDelayMilliseconds); } } }while (!success); }
public void Execute() { TargetTask.Execute(); }