예제 #1
0
        private async Task <string> Listen()
        {
            var startedAt    = DateTime.UtcNow;
            var cycleId      = Guid.NewGuid();
            var exception    = default(Exception);
            var eventIdArray = new long[0];

            try
            {
                if (!_initialized)
                {
                    await _queueDbAccessManager.CreateQueueDbIfNeeded();

                    await _queueDbAccessManager.RegisterSubscriberIfNeeded();

                    _initialized = true;
                }

                var eventArray = await _queueDbAccessManager.GetEvents();

                eventIdArray = eventArray.Select(e => e.Id).ToArray();
                var eventListenerInfo = new EventListenerInfo(cycleId, eventIdArray, startedAt);

                foreach (var @event in eventArray)
                {
                    @event.SetListener(eventListenerInfo);
                    _eventHandlerActor.Tell(@event);
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            var logContent = new
            {
                message = exception == null ? "Listener cycle completed." : "Listener cycle completed with error.",
                cycleId,
                startedAt,
                events      = eventIdArray,
                readingTime = $"{Math.Round((DateTime.UtcNow - startedAt).TotalMilliseconds)}ms"
            };

            Log.Logger.Write(exception == null ? LogEventLevel.Debug : LogEventLevel.Error, exception, "content: {content}", logContent.ToJson(Formatting.Indented));

            return(ScheduleNextListenCommand);
        }
예제 #2
0
파일: Event.cs 프로젝트: lulzzz/Emerald
 public void SetListener(EventListenerInfo listener)
 {
     Listener = listener;
 }