public TaskExecutor( ITaskStepExecutorResolver taskStepExecutorResolver, ExecutionEventsBag executionEventsBag) { _taskStepExecutorResolver = taskStepExecutorResolver; _executionEventsBag = executionEventsBag; }
public TaskExecutor( ITaskStepExecutorResolver taskStepExecutorResolver, ExecutionEventsBag globalEventsBag) { _taskStepExecutorResolver = taskStepExecutorResolver; _globalEventsBag = globalEventsBag; }
public ExecutionEventsBag( ExecutionEventsBag other1, ExecutionEventsBag other2) { _events = other1._events.Merge( other2._events, (x, y) => x.Merge(y)); }
private void ExecuteStep <TStep>( TStep step, TaskDefinition task, TaskOutcome outcomeSoFar, CancellationToken cancellation, ExecutionEventsBag eventsBag) where TStep : ITaskStep { var stepExecutor = _taskStepExecutorResolver.Resolve <TStep>(); var context = new TaskStepExecutionContext( task, eventsBag, outcomeSoFar); stepExecutor.Execute(step, context, cancellation); }
public TaskResult Execute( TaskDefinition task, CancellationToken?cancellation = null, params IExecutionEvents[] events) { if (cancellation == null) { cancellation = CancellationToken.None; } var eventsBag = new ExecutionEventsBag(_globalEventsBag, new ExecutionEventsBag(events)); var outcomeSoFar = TaskOutcome.Successful; var errors = new List <TaskExecutionException>(); var taskEvents = eventsBag.TryGetEvents <TaskExecutionEvents>(); var taskSw = new Stopwatch(); var stepSw = new Stopwatch(); taskEvents?.Raise(x => x.OnTaskStarted(task)); taskSw.Start(); foreach (var step in task.Steps) { if (!step.ExecutionCondition(outcomeSoFar)) { taskEvents?.Raise(x => x.OnStepSkipped(step, task)); continue; } taskEvents?.Raise(x => x.OnStepStarted(step, task)); stepSw.Restart(); try { ExecuteStepMethod.InvokeAsGeneric( this, new[] { step.GetType() }, step, task, outcomeSoFar, cancellation, eventsBag); } catch (OperationCanceledException e) { if (outcomeSoFar < TaskOutcome.Canceled) { outcomeSoFar = TaskOutcome.Canceled; } taskEvents?.Raise(x => x.OnStepCanceled(step, task)); } catch (TaskExecutionException e) { errors.Add(e); if (outcomeSoFar < TaskOutcome.Failed) { outcomeSoFar = TaskOutcome.Failed; } taskEvents?.Raise(x => x.OnStepFailed(e, step, task)); } stepSw.Stop(); taskEvents?.Raise(x => x.OnStepEnded(step, task, stepSw.Elapsed)); } var result = new TaskResult( outcomeSoFar == TaskOutcome.Canceled, errors); taskSw.Stop(); taskEvents?.Raise(x => x.OnTaskEnded(task, result, taskSw.Elapsed)); return(result); }