Пример #1
0
        /// <summary>	Constructor for internal uses only -- specifically. </summary>
        /// <remarks>	7/28/2011. </remarks>
        /// <exception cref="ArgumentNullException">	    Thrown when either the queue or scheduler are null. </exception>
        /// <exception cref="ArgumentOutOfRangeException">	Thrown when the pollingInterval is below the minimum allowed threshold or greater
        /// than the maximum allowed threshold.  Thrown when the items to publish per interval is
        /// less than 1 or greater than the maximum allowed threshold.  </exception>
        /// <param name="durableJobQueue">						Queue of durable jobs. </param>
        /// <param name="maxQueueItemsToPublishPerInterval">	The maximum queue items to publish per interval. </param>
        /// <param name="pollingInterval">						The polling interval. </param>
        /// <param name="scheduler">							The scheduler. </param>
        internal DurableJobQueueMonitor(IDurableJobQueue <TQueue, TQueuePoison> durableJobQueue,
                                        int maxQueueItemsToPublishPerInterval, TimeSpan pollingInterval, IScheduler scheduler)
        {
            if (null == durableJobQueue)
            {
                throw new ArgumentNullException("durableJobQueue");
            }
            if (pollingInterval > DurableJobQueueMonitor.MaximumAllowedPollingInterval)
            {
                throw new ArgumentOutOfRangeException("pollingInterval", String.Format(CultureInfo.CurrentCulture, "must be less than {0:c}", DurableJobQueueMonitor.
                                                                                       MaximumAllowedPollingInterval.ToString()));
            }
            if (pollingInterval < DurableJobQueueMonitor.MinimumAllowedPollingInterval)
            {
                throw new ArgumentOutOfRangeException("pollingInterval", String.Format(CultureInfo.CurrentCulture, "must be at least {0:c}", DurableJobQueueMonitor.
                                                                                       MinimumAllowedPollingInterval));
            }

            if (maxQueueItemsToPublishPerInterval > DurableJobQueueMonitor.MaxAllowedQueueItemsToPublishPerInterval)
            {
                throw new ArgumentOutOfRangeException("maxQueueItemsToPublishPerInterval", String.Format(CultureInfo.CurrentCulture,
                                                                                                         "limited to {0} items to publish per interval", DurableJobQueueMonitor.MaxAllowedQueueItemsToPublishPerInterval));
            }
            if (maxQueueItemsToPublishPerInterval < 1)
            {
                throw new ArgumentOutOfRangeException("maxQueueItemsToPublishPerInterval", "must be at least 1");
            }
            if (null == scheduler)
            {
                throw new ArgumentNullException("scheduler");
            }

            this._durableJobQueue = durableJobQueue;
            this._maxQueueItemsToPublishPerInterval = maxQueueItemsToPublishPerInterval;
            this._pollingInterval = pollingInterval;

            //on first construction, we must move any items out of 'pending' and back into 'queued', in the event of a crash recovery, etc
            durableJobQueue.ResetAllPendingToQueued();

            //fire up our polling on an interval, slurping up all non-nulls from 'queued', to a max of X items, but don't start until connect is called
            _syncRequestPublisher = Observable.Interval(pollingInterval, scheduler)
                                    .SelectMany(interval =>
                                                ReadQueuedItems()
                                                .TakeWhile(request => request.Success)
                                                .Take(maxQueueItemsToPublishPerInterval))
                                    .Select(item => item.Value)
                                    .Publish()
                                    .RefCount();
        }
Пример #2
0
 /// <summary>	Resets all pending items to the queued state. </summary>
 public void ResetAllPendingToQueued()
 {
     _durableJobQueue.ResetAllPendingToQueued();
 }