Пример #1
0
        public bool SendPostsToProcess(IEnumerable <Post> posts, string likerBlogName = null, bool terminateRecursion = false)
        {
            Post[] postsArray = posts.ToArray();

            StripSmallPlayers(postsArray); // minimize the size by including only the largest player

            PostsToProcess postsToProcess = new PostsToProcess
            {
                Posts         = postsArray,
                LikerBlogname = likerBlogName
            };
            string jsonMessage = JsonConvert.SerializeObject(postsToProcess, JsonSerializerSettings);

            if (jsonMessage.Length > 45000)
            {
                if (postsArray.Length > 1)
                {
                    int half = postsArray.Length / 2;

                    Post[] posts1 = postsArray.Take(half).ToArray();
                    SendPostsToProcess(posts1, likerBlogName);

                    Post[] posts2 = postsArray.Skip(half).Take(postsArray.Length - half).ToArray();
                    SendPostsToProcess(posts2, likerBlogName);

                    return(true);
                }

                if (!terminateRecursion)
                {
                    bool result = SendPostsToProcess(postsArray, likerBlogName, true);
                    if (!result)
                    {
                        log.Error("Single post too long (" + jsonMessage.Length + " chars)");
                    }
                    return(result);
                }

                return(false);
            }

            CloudQueueMessage message = new CloudQueueMessage(jsonMessage);

            postsToProcessQueue.AddMessage(message);
            return(true);
        }
Пример #2
0
        public static async Task Run([QueueTrigger(Constants.PostsToProcessQueueName, Connection = "AzureWebJobsStorage")] string myQueueItem, TraceWriter log)
        {
            Startup.Init();

            PostsToProcess postsToProcess = JsonConvert.DeserializeObject <PostsToProcess>(myQueueItem);

            PostProcessor postProcessor = new PostProcessor();

            postProcessor.Init(log);

            try
            {
                await postProcessor.ProcessPosts(postsToProcess.Posts, log, postsToProcess.LikerBlogname);
            }
            catch (Exception ex)
            {
                log.Error("Error", ex);
                throw;
            }
        }