Beispiel #1
0
        private async Task<BlogSyncResult> UpdateBlog(string blogKey, bool forceShouldUpdate)
        {
            var stopwatch = Stopwatch.StartNew();

            var result = new BlogSyncResult(blogKey);

            string lockKey = blogKey.ToLowerInvariant();

            try
            {
                var blogSetting = this.blogSettings.GetBlogSetting(blogKey);

                await UpdateBlogLocker.RunWithLock(
                    lockKey,
                    async () =>
                        {
                            var lastUpdatedAt = !forceShouldUpdate
                                                    ? await this.Config.DataStorage.GetLastUpdatedAt(blogSetting)
                                                    : null;

                            await this.UpdateBlogData(blogSetting, lastUpdatedAt, result);
                        });
            }
            finally
            {
                if (stopwatch != null)
                {
                    stopwatch.Stop();

                    result.Elapsed = stopwatch.Elapsed;
                }
            }

            return result;
        }
Beispiel #2
0
        private async Task UpdateBlogData(BlogSetting blogSetting, DateTime? lastUpdatedAt, BlogSyncResult result)
        {
            var updateMetaTask = this.metaHelper.Update(blogSetting, lastUpdatedAt);
            var updatePostsTask = this.postsHelper.Update(blogSetting, lastUpdatedAt);

            await Task.WhenAll(updateMetaTask, updatePostsTask);

            var meta = updateMetaTask.Result;
            var changeSet = updatePostsTask.Result;

            result.OnDataUpdated(meta, changeSet);

            var saveBlogMetaTask = (meta != null)
                                       ? this.Config.DataStorage.SaveBlogMeta(blogSetting, meta)
                                       : Task.CompletedTask;
            var saveChangesTask = (changeSet != null)
                                      ? this.Config.DataStorage.SaveChanges(blogSetting, changeSet)
                                      : Task.CompletedTask;

            await Task.WhenAll(saveBlogMetaTask, saveChangesTask);
        }