protected virtual void QueryStorage(List <int> activeDeliveryTypes)
        {
            //update query state
            _lastQueryTimeUtc            = DateTime.UtcNow;
            _lastQueryKeys               = activeDeliveryTypes;
            _isLastQueryMaxItemsReceived = false;

            //query items
            Stopwatch storageQueryTimer = Stopwatch.StartNew();
            DateTime  lockStartUtc      = DateTime.UtcNow;

            List <SignalDispatch <TKey> > items = null;

            try
            {
                items = PickStorageQuery(activeDeliveryTypes);
            }
            catch (Exception ex)
            {
                items = new List <SignalDispatch <TKey> >();
                _logger.LogError(ex, SenderInternalMessages.DatabaseDispatchProvider_DatabaseError);
            }
            storageQueryTimer.Stop();

            //enqueue items for processing
            _dispatchQueue.Append(items, true);

            //turn on database event tracking
            _isLastQueryMaxItemsReceived = items.Count == ItemsQueryCount;
            if (_changeNotifier != null && _isLastQueryMaxItemsReceived == false)
            {
                _changeNotifier.StartMonitor();
            }

            //store metrics
            _monitor.DispatchPersistentStorageQueried(storageQueryTimer.Elapsed, items);

            //remember processed items, not to query them again while processing
            _lockTracker.RememberLock(items.Select(x => x.SignalDispatchId), lockStartUtc);
        }
Ejemplo n.º 2
0
        public virtual async Task EnqueueDispatch(SignalDispatch <TKey> signalDispatch, SignalWriteConcern writeConcern)
        {
            writeConcern = _senderSettings.GetWriteConcernOrDefault(writeConcern);
            bool ensurePersisted = writeConcern == SignalWriteConcern.PersistentStorage;

            if (ensurePersisted)
            {
                if (_senderSettings.IsDbLockStorageEnabled)
                {
                    signalDispatch.LockedBy       = _senderSettings.LockedByInstanceId;
                    signalDispatch.LockedSinceUtc = DateTime.UtcNow;
                }
                await _dispatchQueries.Insert(new List <SignalDispatch <TKey> > {
                    signalDispatch
                })
                .ConfigureAwait(false);
            }

            var signalWrapper = new SignalWrapper <SignalDispatch <TKey> >(signalDispatch, ensurePersisted);

            _dispatchQueue.Append(signalWrapper);

            _monitor.DispatchTransferred(signalDispatch);
        }
Ejemplo n.º 3
0
        protected virtual EventHandleResult <SignalDispatch <TKey> > ComposeDispatches(SignalWrapper <SignalEvent <TKey> > @event)
        {
            //find matching EventHandler
            EventSettings <TKey> eventSettings = _eventSettingsQueries.Select(@event.Signal.EventSettingsId.Value).Result;

            if (eventSettings == null)
            {
                return(EventHandleResult <SignalDispatch <TKey> > .FromResult(ProcessingResult.NoHandlerFound));
            }

            IEventHandler <TKey> eventHandler = _handlerRegistry.MatchHandler(eventSettings.EventHandlerId);

            if (eventHandler == null)
            {
                return(EventHandleResult <SignalDispatch <TKey> > .FromResult(ProcessingResult.NoHandlerFound));
            }

            //compose dispatches for subscribers
            EventHandleResult <SignalDispatch <TKey> > composeResult = eventHandler.ProcessEvent(eventSettings, @event.Signal);

            if (composeResult.Result != ProcessingResult.Success)
            {
                return(composeResult);
            }

            //enqueue dispatches
            _dispatchQueue.Append(composeResult.Items, false);

            @event.IsUpdated = true;
            if (composeResult.IsFinished == false)
            {
                composeResult.Result = ProcessingResult.Repeat;
            }

            return(composeResult);
        }