Beispiel #1
0
		private async Task ProcessResultAsync ( IQueuedTaskToken queuedTaskToken,
			TaskExecutionResult result )
		{
			try
			{
				//Update worker execution stats
				UpdateTaskProcessingStats( result );

				//There is no result - most likely, no executor found;
				//	nothing to process, just stop and return
				if ( !result.HasResult )
				{
					mLogger.Debug( "No result info returned. Task will be discarded." );
					return;
				}

				//Execution has been cancelled, usually as a response 
				//	to a cancellation request;
				//	nothing to process, just stop and return
				if ( result.ExecutionCancelled )
				{
					mLogger.Debug( "Task execution cancelled. Task will be discarded." );
					return;
				}

				//Update execution result and see whether 
				//	we need to repost the task to retry its execution
				QueuedTaskInfo repostWithInfo = queuedTaskToken
					.UdpateFromExecutionResult( result );

				//Post result
				mLogger.Debug( "Will post task execution result." );
				await mTaskResultQueue.PostResultAsync( queuedTaskToken );
				mLogger.Debug( "Successfully posted task execution result." );

				//If the task needs to be reposted, do so
				if ( repostWithInfo != null )
				{
					mLogger.Debug( "Will repost task for execution." );
					await mTaskQueueProducer.EnqueueAsync( repostWithInfo );
					mLogger.Debug( "Sucessfully reposted task for execution." );
				}
				else
					mLogger.Debug( "Will not repost task for execution." );

				//Finally, report execution time
				await mPerformanceMonitor.ReportExecutionTimeAsync( queuedTaskToken,
					result );
			}
			catch ( Exception exc )
			{
				mLogger.Error( "Failed to set queued task result. Task will be discarded.",
					exc );
			}
		}
Beispiel #2
0
        public async Task ScheduleFilesAsync(ISourceFileRepository sourceFileRepository, IProcessingWatcher processingWatcher)
        {
            if (sourceFileRepository == null)
            {
                throw new ArgumentNullException(nameof(sourceFileRepository));
            }

            foreach (Guid fileHandleId in sourceFileRepository.AllFileHandleIds)
            {
                await mTaskQueueProducer.EnqueueAsync <HashFileByHandle>(new HashFileByHandle( fileHandleId ),
                                                                         source : nameof(ScheduleFilesAsync),
                                                                         priority : 0);
            }
        }
        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);
        }