Пример #1
0
        public bool TryGetJob(out Job job)
        {
            lock (_locker)
            {
                job = null;

                var jobInWork = _jobs.FirstOrDefault(x => !x.InWork && !x.IsArchived);

                if (jobInWork is null)
                {
                    JobsInQueue.Reset();
                    return(false);
                }

                jobInWork.Work();

                job = jobInWork.Job;

                if (_jobs.Count(x => !x.InWork && !x.IsArchived) == 0)
                {
                    JobsInQueue.Reset();
                }

                return(true);
            }
        }
Пример #2
0
        public void JobUnWork(Job job)
        {
            lock (_locker)
            {
                _jobs.FirstOrDefault(x => x.Job.JobName == job.JobName)?.UnWork();
            }

            JobsInQueue.Set();

            _logger?.Verbose($"Job {job.JobName} has updated in queue {Name} to {job}");
        }
Пример #3
0
        public IHttpActionResult QueryProcessTaskStatus(JobsInQueue jobsInQueue)
        {
            var details = jobQueueService.QueryJobsStatus(jobsInQueue.CreatedJobIds);

            jobsInQueue.CompleteJobIds   = details.Where(x => x.ProcessStatus == ProcessStatus.Completed).Select(x => x.Id.ToString()).ToList();
            jobsInQueue.ErrorJobIds      = details.Where(x => x.ProcessStatus == ProcessStatus.FailToPublish || x.ResultStatus == ResultStatus.Error).Select(x => x.Id.ToString()).ToList();
            jobsInQueue.ProcessingJobIds = details.Where(x => x.ProcessStatus == ProcessStatus.Processing).Select(x => x.Id.ToString()).ToList();
            jobsInQueue.SuccessJobIds    = details.Where(x => x.ResultStatus == ResultStatus.Success).Select(x => x.Id.ToString()).ToList();

            return(Ok(jobsInQueue));
        }
Пример #4
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                JobsInQueue?.Dispose();
            }

            _disposed = true;
        }
Пример #5
0
        public void UpdateJob(Job job)
        {
            if (job is null)
            {
                return;
            }

            lock (_locker)
            {
                _jobs.FirstOrDefault(x => x.Job.JobName == job.JobName)?.Update(job);
            }

            JobsInQueue.Set();
        }
Пример #6
0
        public void AddLast(Job job)
        {
            if (job is null)
            {
                _logger?.Warning("Job is null.");

                return;
            }

            lock (_locker)
            {
                if (_jobs.Any(x => x.Job.Id == job.Id))
                {
                    return;
                }

                _jobs.AddLast(new JobInWork(job));

                _logger?.Verbose($"Job has added to end of {Name}: {job}.");
            }

            JobsInQueue.Set();
        }