public async Task Consume(ConsumeContext <FeedDataSourceUnsubscribedEvent> context)
        {
            var datasource = await _datasourceCommandRepository.Get(context.Message.DataSourceId, CancellationToken.None);

            datasource.DecrementFollower();
            await _datasourceCommandRepository.Update(new[] { datasource }, CancellationToken.None);

            await _datasourceCommandRepository.SaveChanges(CancellationToken.None);
        }
Beispiel #2
0
        public async Task Consume(ConsumeContext <ArticleAddedEvent> context)
        {
            var directoryInfo = ArticleExtractorJob.GetDirectory();
            var lck           = new FileDistributedLock(directoryInfo, "article-added");

            using (var distributedLock = await lck.TryAcquireAsync())
            {
                if (distributedLock == null)
                {
                    var random = new Random();
                    Thread.Sleep(random.Next(100, 2000));
                    return;
                }

                var datasource = await _dataSourceCommandRepository.Get(context.Message.DataSourceId, CancellationToken.None);

                datasource.AddArticle(context.Message.PublishDate);
                await _dataSourceCommandRepository.Update(new[] { datasource }, CancellationToken.None);

                await _dataSourceCommandRepository.SaveChanges(CancellationToken.None);
            }
        }