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); }
public void SetListener(EventListenerInfo listener) { Listener = listener; }