Exemplo n.º 1
0
        private void ProcessSpecificGroupFeeds(FeedProcessingConfig processingConfig)
        {
            using (ICommandReceiver groupReceiver = Factory.GetInstance <ICommandReceiver>().Open(processingConfig.GroupQueueId))
            {
                while (true)
                {
                    GroupQueueItem commandMessage = null;

                    try
                    {
                        commandMessage = groupReceiver.GetCommand <GroupQueueItem>();

                        if (commandMessage == null)
                        {
                            this.log.Error("No groups found to process. Processing stopped.");
                            return;
                        }

                        this.ProcessGroup(commandMessage.VkGroupId);
                    }
                    catch (Exception exc)
                    {
                        this.log.ErrorFormat("Exception is occured while processing a group Id = {0}: {1}", commandMessage != null ? commandMessage.VkGroupId : 0, exc.ToString());
                        return;
                    }
                    finally
                    {
                        if (commandMessage != null)
                        {
                            commandMessage.MarkAsCompleted();

                            using (ICommandSender groupSender = Factory.GetInstance <ICommandSender>().Open(processingConfig.GroupQueueId))
                            {
                                groupSender.SendCommand(new GroupQueueItem(commandMessage.VkGroupId));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
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));
            }
        }