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)); }
public void RetryOrPoison(Job job, Exception exception, JobContext context) { if (job == null) { throw new ArgumentNullException("job"); } if (exception == null) { throw new ArgumentNullException("exception"); } if (context == null) { throw new ArgumentNullException("context"); } var config = _configuration.For(job.Type); if (job.DispatchCount <= config.RetryCount) { _recoverableAction.Run(() => job = _statusChanger.Change(job, JobStatus.Failed), then: () => _failedJobQueue.Add(job)); } else { context.Exception = exception; _jobCoordinator.Run(job, () => _statusChanger.Change(job, JobStatus.Poisoned)); } }
/// <summary> /// Finds all schedulable jobs that are in /// Created state. Then for each of them, /// attempts to update the status to Ready. /// Once successful, routes the job. /// </summary> void DispatchCore(IEnumerable <Continuation> readyContinuations) { var schedulableJobs = ( from @await in readyContinuations let j = _persistenceStore.Load(@await.Id) where j.Status == JobStatus.Created select j) .ToArray(); foreach (var job in schedulableJobs) { var jobReference = job; _recoverableAction.Run( () => jobReference = _jobMutator.Mutate <ContinuationDispatcher>(jobReference, JobStatus.Ready), then: () => _router.Route(jobReference)); } }
public Job Transit(Job job, Activity activity) { if (job == null) { throw new ArgumentNullException("job"); } if (activity == null) { throw new ArgumentNullException("activity"); } var converted = _activityToContinuationConverter.Convert(activity, job); _persistenceStore.Store(converted.Jobs); job = _jobMutator.Mutate <WaitingForChildrenTransition>(job, status: JobStatus.WaitingForChildren, continuation: converted.Continuation); _recoverableAction.Run(() => _continuationDispatcher.Dispatch(job)); return(job); }