protected void Dispose ( bool disposing ) { if ( !mIsDisposed ) { if ( disposing ) { //Ensure we have stopped StopAync().Wait(); //Clear wait handles mWaitForClearToFetchTask.Dispose(); mWaitForClearToFetchTask = null; //It is not our responsibility // to dispose of these dependencies // since we are not the owner and we // may interfere with their orchestration mTaskBuffer = null; mExecutorRegistry = null; mPayloadTypes = null; mStateController = null; mTaskQueueProducer = null; mTaskResultQueue = null; } mIsDisposed = true; } }
public StandardTaskWorker ( TaskProcessingOptions options, ITaskBuffer taskBuffer, ITaskExecutorRegistry executorRegistry, IExecutionPerformanceMonitor performanceMonitor, ITaskQueueProducer taskQueueProducer, ITaskResultQueue taskResultQueue ) { mOptions = options ?? throw new ArgumentNullException( nameof( options ) ); mTaskBuffer = taskBuffer ?? throw new ArgumentNullException( nameof( taskBuffer ) ); mExecutorRegistry = executorRegistry ?? throw new ArgumentNullException( nameof( executorRegistry ) ); mPerformanceMonitor = performanceMonitor ?? throw new ArgumentNullException( nameof( performanceMonitor ) ); mTaskQueueProducer = taskQueueProducer ?? throw new ArgumentNullException( nameof( taskQueueProducer ) ); mTaskResultQueue = taskResultQueue ?? throw new ArgumentNullException( nameof( taskResultQueue ) ); }
public async Task Test_DoWork_TasksWithErrors_UntilFataled(int workerCount) { ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); int expectedNumberOfErrors = taskEngine.Options .TaskProcessingOptions .FaultErrorThresholdCount + 2; CountdownEvent doneEvent = new CountdownEvent(20 * expectedNumberOfErrors); TestExecutorEventBus <AlwaysFailingTask> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new AlwaysFailingTask(), source : nameof(Test_DoWork_TasksWithErrors_UntilFataled), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus( expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Fatal, expectedErrorCount : expectedNumberOfErrors); await AssertCorrectExecutionCyclesCount <AlwaysFailingTask>(expectedCount : 20 *expectedNumberOfErrors); }
public async Task Test_DoWork_TasksWithErrors_CompletesSuccessfullyAfterFailures(int workerCount) { ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); int numberForErrorsBeforeSucceeding = taskEngine.Options .TaskProcessingOptions .FaultErrorThresholdCount - 1; CountdownEvent doneEvent = new CountdownEvent(20 * (numberForErrorsBeforeSucceeding + 1)); TestExecutorEventBus <FailsNTimesBeforeSucceeding> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new FailsNTimesBeforeSucceeding( Guid.NewGuid(), numberForErrorsBeforeSucceeding ), source : nameof(Test_DoWork_TasksWithErrors_CompletesSuccessfullyAfterFailures), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus(expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Processed, expectedErrorCount : numberForErrorsBeforeSucceeding); await AssertCorrectExecutionCyclesCount <FailsNTimesBeforeSucceeding>(expectedCount : 20 *(numberForErrorsBeforeSucceeding + 1)); }
public async Task Test_DoWork_TasksWithNoErrors(int workerCount) { CountdownEvent doneEvent = new CountdownEvent(20); ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); TestExecutorEventBus <ComputeFactorial> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new ComputeFactorial( i ), source : nameof(Test_DoWork_TasksWithNoErrors), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus( expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Processed, expectedErrorCount : 0); await AssertCorrectExecutionCyclesCount <ComputeFactorial>(expectedCount : 20); }
public AllAtOnceSourceFileScheduler(ITaskQueueProducer taskQueueProducer) { mTaskQueueProducer = taskQueueProducer ?? throw new ArgumentNullException(nameof(taskQueueProducer)); }