コード例 #1
0
        public void TestGetTopItem()
        {
            ExecuteWithTransaction(() =>
            {
                IQueueItemDAL queueItemDAL = IoC.Container.Resolve <IQueueItemDAL>();

                QueueItemDTO queueItem = new QueueItemDTO
                {
                    BadgeAwardId = 1
                };

                QueueItemDTO addedItem = queueItemDAL.Add(queueItem);

                QueueItemDTO topItem = queueItemDAL.Peek();
                Assert.IsTrue(topItem.QueueItemId == addedItem.QueueItemId);
            });
        }
コード例 #2
0
        private static QueueEventLogDTO AddQueueEventLogRecord(IQueueEventLogDAL queueEventLogDAL, IQueueItemDAL queueItemDAL)
        {
            //Grab the top item
            QueueItemDTO queueItemDTO = queueItemDAL.Peek();

            Assert.IsNotNull(queueItemDTO);

            QueueEventLogDTO queueEventLogItem = new QueueEventLogDTO
            {
                Message = "Test Message",
                QueueEventCreated = DateTime.Now,
                QueueEventId = 1,
                BadgeAwardId = queueItemDTO.QueueItemId
            };

            QueueEventLogDTO addedItem = queueEventLogDAL.Add(queueEventLogItem);
            return addedItem;
        }
コード例 #3
0
        private static QueueEventLogDTO AddQueueEventLogRecord(IQueueEventLogDAL queueEventLogDAL, IQueueItemDAL queueItemDAL)
        {
            //Grab the top item
            QueueItemDTO queueItemDTO = queueItemDAL.Peek();

            Assert.IsNotNull(queueItemDTO);

            QueueEventLogDTO queueEventLogItem = new QueueEventLogDTO
            {
                Message           = "Test Message",
                QueueEventCreated = DateTime.Now,
                QueueEventId      = 1,
                BadgeAwardId      = queueItemDTO.QueueItemId
            };

            QueueEventLogDTO addedItem = queueEventLogDAL.Add(queueEventLogItem);

            return(addedItem);
        }
コード例 #4
0
        /// <summary>
        /// This method runs the queue process
        /// </summary>
        public void Start()
        {
            var consecutiveErrorCount = 0;

            Logger.Info <QueueProcessor>("The Queue Processor was started");

            while (true)
            {
                try
                {
                    QueueItemDTO latestItem = _queueItemDAL.Peek();

                    if (latestItem != null)
                    {
                        Logger.InfoFormat <QueueProcessor>("Processor peeked item with QueueItemId: {0} and BadgeAwardId: {1}, processing...",
                                                           latestItem.QueueItemId,
                                                           latestItem.BadgeAwardId);

                        _itemProcessor.ProcessItem(latestItem);
                    }
                    else
                    {
                        Logger.InfoFormat <QueueProcessor>("No items found in the queue, sleeping for {0} seconds", SleepInterval / 1000);

                        Thread.Sleep(SleepInterval);
                    }
                    consecutiveErrorCount = 0;
                }
                catch (Exception ex)
                {
                    Logger.Error <QueueProcessor>(ex.Message, ex);
                    consecutiveErrorCount++;
                    if (consecutiveErrorCount >= 5)
                    {
                        //Continuous logging of an error in a tight loop is bad, go to sleep and see if the system
                        //recovers
                        Logger.InfoFormat <QueueProcessor>("Queue processor consecutive error limit exceeded, sleeping for {0} seconds", ErrorSleepInterval / 1000);
                        Thread.Sleep(ErrorSleepInterval);
                    }
                }
            }
        }