Пример #1
0
        Job EndTree(Job job, JobStatus endStatus)
        {
            // If this is the root, mutate to completed status.
            if (job.ParentId == null)
            {
                return(_jobMutator.Mutate <EndTransition>(job, status: JobStatus.Completed));
            }

            job = _jobMutator.Mutate <EndTransition>(job, PendingEndStatus[endStatus]);

            /*
             * First, load the parent, find the await record for this job and
             * update its status to end status.
             */
// ReSharper disable once PossibleInvalidOperationException
            var parent = _jobRepository.Load(job.ParentId.Value);
            var @await = parent.Continuation.Find(job);

            @await.Status = endStatus;

            /*
             * After we set the await's status, invoke ContinuationDispatcher to
             * ensure any pending await for parent is dispatched.
             * If ContinuationDispatcher returns any awaits, that means parent job is not
             * ready for completion.
             */
            var pendingAwaits = _continuationDispatcher.Dispatch(parent);

            if (!pendingAwaits.Any())
            {
                EndTree(parent, JobStatus.Completed);
            }

            return(_jobMutator.Mutate <EndTransition>(job, endStatus));
        }
Пример #2
0
        public void Verify(Guid id)
        {
            // First load the current version of job
            var currentJob = _persistenceStore.Load(id);

            if (currentJob.Status != JobStatus.WaitingForChildren)
            {
                return;
            }

            _continuationDispatcher.Dispatch(currentJob);
        }
Пример #3
0
        void OnTick(object state)
        {
            var ready    = new Collection <Tuple <Guid, DateTime?> >();
            var notReady = new Collection <Tuple <Guid, DateTime?> >();

            try
            {
                Tuple <Guid, DateTime?> item;

                _eventStream.Publish <FailedJobQueue>(
                    EventType.TimerActivity,
                    EventProperty.ActivityName("RescheduleFailedJobs"),
                    EventProperty.Named("FailedItemsQueueLength", _jobFailures.Count));

                while (_jobFailures.TryTake(out item))
                {
                    if (item.Item2 < _now())
                    {
                        ready.Add(item);
                    }
                    else
                    {
                        notReady.Add(item);
                    }
                }

                foreach (var job in ready.Select(i => _persistenceStore.Load(i.Item1)))
                {
                    _router.Route(job);
                }

                ready.Clear();
            }
            catch (Exception e)
            {
                if (e.IsFatal())
                {
                    throw;
                }

                _eventStream.Publish <FailedJobQueue>(e);
            }
            finally
            {
                foreach (var item in ready.Concat(notReady))
                {
                    _jobFailures.Add(item);
                }

                _timer.Change(_configuration.RetryTimerInterval, Timeout.InfiniteTimeSpan);
            }
        }
Пример #4
0
		/// <summary>
		/// Creates shared object with given parent scope, name, persistence flag state and store object.
		/// </summary>
		/// <param name="parent"></param>
		/// <param name="name"></param>
		/// <param name="persistent"></param>
		/// <param name="store"></param>
		public SharedObjectScope(IScope parent, string name, bool persistent, IPersistenceStore store)
			: base(parent, SharedObjectService.ScopeType, name, persistent) {
			string path = parent.ContextPath;
			if (!path.StartsWith("/"))
				path = "/" + path;
			// Create shared object wrapper around the attributes
			_so = store.Load(name) as SharedObject;
			if (_so == null) {
				_so = new SharedObject(_attributes, name, path, persistent, store);
				store.Save(_so);
			} else {
				_so.Name = name;
				_so.Path = parent.ContextPath;
				_so.Store = store;
			}
		}
Пример #5
0
        /// <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));
            }
        }
Пример #6
0
        /// <summary>
        /// Creates shared object with given parent scope, name, persistence flag state and store object.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="name"></param>
        /// <param name="persistent"></param>
        /// <param name="store"></param>
        public SharedObjectScope(IScope parent, string name, bool persistent, IPersistenceStore store) : base(parent, SharedObjectService.ScopeType, name, persistent)
        {
            string path = parent.ContextPath;

            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            // Create shared object wrapper around the attributes
            _so = store.Load(name) as SharedObject;
            if (_so == null)
            {
                _so = new SharedObject(_attributes, name, path, persistent, store);
                store.Save(_so);
            }
            else
            {
                _so.Name  = name;
                _so.Path  = parent.ContextPath;
                _so.Store = store;
            }
        }
Пример #7
0
        public SharedObjectScope(IScope parent, string name, bool persistent, IPersistenceStore store) : base(parent, SharedObjectService.ScopeType, name, persistent)
        {
            this._serverListeners  = new CopyOnWriteArray();
            this._handlers         = new Hashtable();
            this._securityHandlers = new CopyOnWriteArray();
            string contextPath = parent.ContextPath;

            if (!contextPath.StartsWith("/"))
            {
                contextPath = "/" + contextPath;
            }
            this._so = store.Load(name) as SharedObject;
            if (this._so == null)
            {
                this._so = new SharedObject(base._attributes, name, contextPath, persistent, store);
                store.Save(this._so);
            }
            else
            {
                this._so.Name  = name;
                this._so.Path  = parent.ContextPath;
                this._so.Store = store;
            }
        }