Пример #1
0
        private async Task <CoreTestContext> ExecuteOrchestrator(
            int jobsterCount,
            int batchSize,
            bool jobsterThrowsExceptionInTheMiddle = false,
            ExceptionPolicy exceptionPolicy        = ExceptionPolicy.NoThrow,
            CoreTestContext context = null,
            IEnumerable <IJobsterAsync <CoreTestContext> > state     = null,
            MemoryJobsterStateHandler <CoreTestContext> stateHandler = null,
            IProgressNotifier <CoreTestContext> progressNotifier     = null)
        {
            context ??= new CoreTestContext();
            int middleJobster = jobsterCount / 2;

            IList <IJobsterAsync <CoreTestContext> > jobsters = new List <IJobsterAsync <CoreTestContext> >(jobsterCount);

            for (int i = 0; i < jobsterCount; i++)
            {
                jobsters.Add(new TestJobster(
                                 context,
                                 jobsterThrowsExceptionInTheMiddle && i == middleJobster));
            }

            JobsterBuilder <CoreTestContext> builder = new JobsterBuilder <CoreTestContext>(_mockLogger)
                                                       .AddBatchSize(batchSize)
                                                       .AddExceptionPolicy(exceptionPolicy)
                                                       .AddJobsters(jobsters.ToArray())
                                                       .AddStateHandler(stateHandler ?? new MemoryJobsterStateHandler <CoreTestContext>(
                                                                            state ?? new IJobsterAsync <CoreTestContext> [0]));

            if (progressNotifier != null)
            {
                builder.AddProgressNotifier(progressNotifier);
            }

            _ = await builder
                .BuildEngine()
                .ScheduleJobstersAsync(_cancellationTokenSource.Token);

            return(context);
        }
Пример #2
0
        private static async Task Main(string[] args)
        {
            using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                .SetMinimumLevel(LogLevel.Debug)
                .AddConsole();
            });
            ILogger logger = loggerFactory.CreateLogger <ConsoleConsumer>();
            ILogger <ConsumerJobster> jobsterLogger = loggerFactory.CreateLogger <ConsumerJobster>();

            LocalEventProgressNotifier <ConsumerContext> progressNotifier = new LocalEventProgressNotifier <ConsumerContext>();

            progressNotifier.NotifyEvent += (jobster, progress) =>
                                            logger.LogInformation($"Jobster with ID={jobster.JobId} has finished. Current progress: {progress.Completed}/{progress.All}");

            ConsumerContext consumerContext = new ConsumerContext();
            IList <IJobsterAsync <ConsumerContext> > jobsters = new List <IJobsterAsync <ConsumerContext> >(100);

            for (int i = 0; i < 100; i++)
            {
                jobsters.Add(new ConsumerJobster(
                                 jobsterLogger,
                                 consumerContext));
            }

            IOrchestnationEngine <ConsumerContext> jobsterEngine = new JobsterBuilder <ConsumerContext>(logger)
                                                                   .AddBatchSize(10)
                                                                   .AddJobsters(jobsters.ToArray())
                                                                   .AddProgressNotifier(progressNotifier)
                                                                   .AddStateHandler(new FileJobsterStateHandler <ConsumerContext>(@"saved_state.json"))
                                                                   .BuildEngine();

            CancellationTokenSource cancellationToken = new CancellationTokenSource();
            IList <IJobsterAsync <ConsumerContext> > resultJobsters = await jobsterEngine.ScheduleJobstersAsync(cancellationToken.Token);

            logger.LogInformation($"Finished, result: {resultJobsters.First().Context.Counter}");
            Console.ReadKey();
        }
Пример #3
0
 public void Setup()
 {
     _jobsterBuilder = new JobsterBuilder <CoreTestContext>(new Mock <ILogger>().Object);
 }