Ejemplo n.º 1
0
        private IEnumerable <FeedQueueItem> GetExistingQueueItems()
        {
            IList <FeedQueueItem> items = new List <FeedQueueItem>();

            java.util.List jobQueueItems = Client.getFeedJobQueueItems(this.jmxConfiguration.AmqJmxUrl, this.jmxConfiguration.BrokerJmxName, "FeedJobQueue");

            for (int i = 0; i < jobQueueItems.size(); i++)
            {
                var queueItem = jobQueueItems.get(i) as string;

                if (queueItem != null)
                {
                    var boxedVkGroupId     = GroupRegex.Match(queueItem).Groups[1].Value;
                    var boxedQueueItemType = QueueItemTypeRegex.Match(queueItem).Groups[1].Value;

                    var item = new FeedQueueItem
                    {
                        VkGroupId     = int.Parse(boxedVkGroupId),
                        QueueItemType = (QueueItemType)Enum.Parse(typeof(QueueItemType), boxedQueueItemType)
                    };
                    items.Add(item);
                }
            }

            return(items);
        }
Ejemplo n.º 2
0
        private FeedQueueItem GetQueueItem(VkGroup @group, QueueItemType dataFeedType)
        {
            FeedQueueItem item = new FeedQueueItem()
            {
                VkGroupId     = @group.Id,
                QueueItemType = dataFeedType,
                CreationDate  = this.dateTimeHelper.GetDateTimeNow(),
            };

            return(item);
        }
Ejemplo n.º 3
0
        private void ProcessQueueItem(FeedQueueItem queueItem, IVkDataProvider vkDataProvider, FeedProcessingConfig processingConfig)
        {
            try
            {
                if (!this.feedProviders.ContainsKey(queueItem.QueueItemType))
                {
                    throw new ArgumentException(string.Format("Unsupported feed type provided: \"{0}\"", queueItem.QueueItemType));
                }

                var feedProvider = this.feedProviders[queueItem.QueueItemType];
                var vkGroup      = this.groupRepository.GetGroupById(queueItem.VkGroupId);

                if (vkGroup == null)
                {
                    this.log.InfoFormat("Group with Id = \"{0}\" not found. Processing stopped.", queueItem.VkGroupId);
                    return;
                }

                this.log.InfoFormat("Fetching of feed '{0}' for VkGroupId {1} is started", queueItem.QueueItemType, queueItem.VkGroupId);

                using (ICommandSender commandSender = Factory.GetInstance <ICommandSender>().Open(processingConfig.OutputQueueId))
                {
                    foreach (var dataFeed in feedProvider.GetFeeds(vkDataProvider, vkGroup))
                    {
                        dataFeed.TtlInMinutes = processingConfig.TtlInMinutes;
                        commandSender.SendCommand(dataFeed);
                    }

                    var terminator = new DataFeed
                    {
                        IsSequenceTerminator = true,
                        ReceivedAt           = this.dateTimeHelper.GetDateTimeNow(),
                        SendingDate          = this.dateTimeHelper.GetDateTimeNow(),
                        VkGroupId            = vkGroup.Id,
                        Type            = feedProvider.ProvidedDataType,
                        FetchingServer  = this.webUtilities.GetServerName(),
                        FetchingProcess = this.webUtilities.GetApplicationPoolName()
                    };

                    commandSender.SendCommand(terminator);
                }

                this.log.InfoFormat("Fetching of feed '{0}' for VkGroupId {1} is finished", queueItem.QueueItemType, queueItem.VkGroupId);
            }
            catch (Exception exc)
            {
                this.log.Error(string.Format("Fetching of feed '{0}' for VkGroupId {1} is FAILED. Reason: {2}", queueItem.QueueItemType, queueItem.VkGroupId, exc));
            }
        }
Ejemplo n.º 4
0
        public void ProcessNextQueueItem()
        {
            this.log.Info("GetFeedsFromVKAction process started");

            var processingConfig = this.configProvider.GetConfigurationSection <FeedProcessingConfig>();
            var selector         = !string.IsNullOrWhiteSpace(processingConfig.FeedFilter) ? processingConfig.FeedFilter : null;

            using (ICommandReceiver commandReceiver = Factory.GetInstance <ICommandReceiver>().Open(processingConfig.InputQueueId, selector))
            {
                IVkDataProvider vkDataProvider = this.vkConnectionBuilder.GetVkDataProvider();

                for (int i = 0; i < CONST_BatchProcessingSize; i++)
                {
                    FeedQueueItem queueItem = null;

                    try
                    {
                        queueItem = commandReceiver.GetCommand <FeedQueueItem>();

                        if (queueItem == null)
                        {
                            this.log.Info("No items in queue found. Processing stopped.");
                            return;
                        }

                        this.ProcessQueueItem(queueItem, vkDataProvider, processingConfig);
                    }
                    finally
                    {
                        if (queueItem != null)
                        {
                            queueItem.MarkAsCompleted();

                            using (ICommandSender commandSender = Factory.GetInstance <ICommandSender>().Open(processingConfig.InputQueueId))
                            {
                                commandSender.SendCommand(queueItem.Copy());
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private IList <FeedQueueItem> GetPossibleQueueItems(IEnumerable <VkGroup> vkGroups, List <QueueItemType> dataFeedTypes)
        {
            IList <FeedQueueItem> possibleItems = new List <FeedQueueItem>();

            foreach (var vkGroup in vkGroups)
            {
                foreach (var dataFeedType in dataFeedTypes)
                {
                    FeedQueueItem item = new FeedQueueItem
                    {
                        VkGroupId     = vkGroup.Id,
                        QueueItemType = dataFeedType,
                        CreationDate  = this.dateTimeHelper.GetDateTimeNow()
                    };

                    possibleItems.Add(item);
                }
            }

            return(possibleItems);
        }