Пример #1
0
        public void Write(Job job)
        {
            var suspendedCount = 0;
            var suspended      = false;

            lock (_queueAccess)
            {
                if (_reader != null && _reader.TrySetResult(job))
                {
                    return;
                }

                // Suspend if this is not the default job queue and this is currently overlfowed.
                if ((_suspendedCount > 0 || _items.Count >= Configuration.MaxQueueLength))
                {
                    _suspendedCount++;
                    suspended      = true;
                    suspendedCount = _suspendedCount;
                }
                else
                {
                    _items.Enqueue(job);
                }
            }

            if (!suspended)
            {
                return;
            }

            _recoverableAction.Run(() => _jobMutator.Mutate <JobQueue>(job, suspended: true));

            _eventStream.Publish <JobQueue>(EventType.JobSuspended, EventProperty.JobSnapshot(job),
                                            EventProperty.Named("SuspendedCount", suspendedCount));
        }
Пример #2
0
        public Job Mutate <TSource>(Job job,
                                    JobStatus?status          = null,
                                    int?dispatchCount         = null,
                                    DateTime?retryOn          = null,
                                    Continuation continuation = null,
                                    bool?suspended            = null)
        {
            var newJob = new Job(job.Id,
                                 job.Type,
                                 job.Method,
                                 job.Arguments,
                                 job.CreatedOn,
                                 job.RootId,
                                 job.ParentId,
                                 job.CorrelationId,
                                 status ?? job.Status,
                                 dispatchCount ?? job.DispatchCount,
                                 retryOn ?? job.RetryOn,
                                 job.ExceptionFilters,
                                 continuation ?? job.Continuation,
                                 suspended ?? job.Suspended);

            _repository.Store(newJob);

            if (job.Status != newJob.Status)
            {
                _eventStream.Publish <TSource>(
                    EventType.JobStatusChanged,
                    EventProperty.JobSnapshot(job),
                    EventProperty.FromStatus(job.Status),
                    EventProperty.ToStatus(newJob.Status));
            }

            return(newJob);
        }
Пример #3
0
        public void Add(Job job)
        {
            _eventStream.Publish <FailedJobQueue>(
                EventType.Activity,
                EventProperty.ActivityName("NewFailedItem"),
                EventProperty.JobSnapshot(job));

            _jobFailures.Add(Tuple.Create(job.Id, job.RetryOn));
        }