Exemplo n.º 1
0
        protected override async Task ProcessItem(string itemId, CancellationToken cancellationToken)
        {
            if (!await _lockProvider.AcquireLock($"evt:{itemId}", cancellationToken))
            {
                Logger.LogInformation($"Event locked {itemId}");
                return;
            }

            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                var evt = await _persistenceStore.GetEvent(itemId);

                if (evt.EventTime <= _datetimeProvider.Now.ToUniversalTime())
                {
                    var subs = await _persistenceStore.GetSubcriptions(evt.EventName, evt.EventKey, evt.EventTime);

                    var success = true;

                    foreach (var sub in subs.ToList())
                    {
                        success = success && await SeedSubscription(evt, sub, cancellationToken);
                    }

                    if (success)
                    {
                        await _persistenceStore.MarkEventProcessed(itemId);
                    }
                }
            }
            finally
            {
                await _lockProvider.ReleaseLock($"evt:{itemId}");
            }
        }
Exemplo n.º 2
0
        private async void RunEvents()
        {
            while (!_shutdown)
            {
                try
                {
                    var eventId = await _queueProvider.DequeueWork(QueueType.Event);

                    if (eventId != null)
                    {
                        if (await _lockProvider.AcquireLock($"evt:{eventId}"))
                        {
                            try
                            {
                                var evt = await _persistenceStore.GetEvent(eventId);

                                if (evt.EventTime <= DateTime.Now.ToUniversalTime())
                                {
                                    var subs = await _persistenceStore.GetSubcriptions(evt.EventName, evt.EventKey, evt.EventTime);

                                    var success = true;

                                    foreach (var sub in subs.ToList())
                                    {
                                        success = success && await SeedSubscription(evt, sub);
                                    }

                                    if (success)
                                    {
                                        await _persistenceStore.MarkEventProcessed(eventId);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                _logger.LogError(ex.Message);
                            }
                            finally
                            {
                                await _lockProvider.ReleaseLock($"evt:{eventId}");
                            }
                        }
                        else
                        {
                            _logger.LogInformation($"Event locked {eventId}");
                        }
                    }
                    else
                    {
                        await Task.Delay(_options.IdleTime); //no work
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
            }
        }
        protected override async Task ProcessItem(string itemId, CancellationToken cancellationToken)
        {
            if (!await _lockProvider.AcquireLock($"evt:{itemId}", cancellationToken))
            {
                Logger.LogInformation($"Event locked {itemId}");
                return;
            }

            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                var evt = await _persistenceStore.GetEvent(itemId);

                if (evt?.EventTime <= _datetimeProvider.Now.ToUniversalTime())
                {
                    var subs = await _persistenceStore.GetSubcriptions(evt.EventName, evt.EventKey, evt.EventTime);

                    var toQueue  = new List <string>();
                    var complete = true;

                    foreach (var sub in subs.ToList())
                    {
                        complete = complete && await SeedSubscription(evt, sub, toQueue, cancellationToken);
                    }

                    if (complete)
                    {
                        await _persistenceStore.MarkEventProcessed(itemId);
                    }

                    foreach (var eventId in toQueue)
                    {
                        await QueueProvider.QueueWork(eventId, QueueType.Event);
                    }
                }
            }
            finally
            {
                await _lockProvider.ReleaseLock($"evt:{itemId}");
            }
        }
Exemplo n.º 4
0
        public async Task PublishEvent(string eventName, string eventKey, object eventData)
        {
            if (_shutdown)
            {
                throw new Exception("Host is not running");
            }

            _logger.LogDebug("Publishing event {0} {1}", eventName, eventKey);
            var subs = await _persistenceStore.GetSubcriptions(eventName, eventKey);

            foreach (var sub in subs.ToList())
            {
                EventPublication pub = new EventPublication();
                pub.Id         = Guid.NewGuid();
                pub.EventData  = eventData;
                pub.EventKey   = eventKey;
                pub.EventName  = eventName;
                pub.StepId     = sub.StepId;
                pub.WorkflowId = sub.WorkflowId;
                await _queueProvider.QueueForPublishing(pub);

                await _persistenceStore.TerminateSubscription(sub.Id);
            }
        }
Exemplo n.º 5
0
 protected IEnumerable <EventSubscription> GetActiveSubscriptons(string eventName, string eventKey)
 {
     return(PersistenceProvider.GetSubcriptions(eventName, eventKey, DateTime.MaxValue).Result);
 }