예제 #1
0
        public async Task ExecuteAsync(
            IJobsterAsync <T> jobsterAsync,
            IJobsterAsync <T>[] requiredJobsterAsync,
            IList <IProgressNotifier <T> > progressNotifiers,
            JobsterProgressModel progressModel)
        {
            try
            {
                await jobsterAsync.ExecuteAsync(requiredJobsterAsync);

                if (JobsterFinishedEvent != null)
                {
                    await JobsterFinishedEvent?.Invoke(jobsterAsync, JobsterStatusEnum.Completed);
                }
            }
            catch (Exception ex)
            {
                if (JobsterFinishedEvent != null)
                {
                    await JobsterFinishedEvent?.Invoke(jobsterAsync, JobsterStatusEnum.Failed, ex);
                }
            }

            foreach (IProgressNotifier <T> progressNotifier in progressNotifiers)
            {
                progressNotifier.Notify(jobsterAsync, progressModel);
            }
        }
예제 #2
0
        private async Task RestoreState()
        {
            if (_jobsterStateHandler == null)
            {
                return;
            }

            IEnumerable <IJobsterAsync <T> > jobsters = await _jobsterStateHandler.RestoreState();

            if (!jobsters.Any(
                    p => p.Status == JobsterStatusEnum.Executing || p.Status == JobsterStatusEnum.NotStarted))
            {
                return;
            }

            _jobsters = new Jobsters <T>(
                jobsters
                .Select(
                    p =>
            {
                p.Logger = _logger;
                return(p);
            })
                .ToList(),
                true);
            _jobsterProgressModel = new JobsterProgressModel(
                _jobsters.JobstersAsync
                .Count(
                    p => p.Status == JobsterStatusEnum.NotStarted ||
                    p.Status == JobsterStatusEnum.Executing));
            _logger.LogInformation("Previous state has been restored, resuming jobsters...");
        }
예제 #3
0
        public BasicEngine(
            ILogger logger,
            IList <IJobsterAsync <T> > jobstersAsync,
            IConfiguration <T> configuration,
            IJobsterStateHandler <T> jobsterStateHandler = null)
        {
            Guard.Argument(jobstersAsync)
            .NotNull();
            Guard.Argument(configuration)
            .NotNull()
            .Member(p => p.JobsterExecutor,
                    u => u.NotNull());

            _logger               = logger;
            _configuration        = configuration;
            _jobsters             = new Jobsters <T>(jobstersAsync);
            _jobsterTasks         = new List <Task>(jobstersAsync.Count);
            _jobsterProgressModel = new JobsterProgressModel(jobstersAsync.Count);
            _jobsterStateHandler  = jobsterStateHandler;

            configuration.JobsterExecutor.JobsterFinishedEvent += OnJobsterFinished;
        }