Exemplo n.º 1
0
        private async static Task ProcessScrapingTask(
            ScrapingTask scrapingTask,
            IGitHubClient gitHubClient,
            ITransaction tx,
            IReliableConcurrentQueue <ScrapingTask> firstTaskQueue,
            IReliableConcurrentQueue <ScrapingTask> secondTaskQueue,
            IUserRepoSearchActorProvider userRepoSearchActorProvider)
        {
            IUserRepoSearchActor userRepoSearchActor =
                userRepoSearchActorProvider.Provide(scrapingTask.UserLogin);

            await Scraper.PerformTaskAsync(
                scrapingTask : scrapingTask, gitHubClient : gitHubClient,
                tx : tx, userRepoSearchActor : userRepoSearchActor,
                firstTaskQueue : firstTaskQueue,
                secondTaskQueue : secondTaskQueue);
        }
Exemplo n.º 2
0
        public async static Task RunAsync(
            CancellationToken cancellationToken,
            IGitHubClient gitHubClient,
            IReliableStateManager stateManager,
            IUserRepoSearchActorProvider userRepoSearchActorProvider)
        {
            IReliableConcurrentQueue <ScrapingTask> firstTaskQueue =
                await GetFirstTaskQueue(stateManager);

            IReliableConcurrentQueue <ScrapingTask> secondTaskQueue =
                await GetSecondTaskQueue(stateManager);

            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (firstTaskQueue.Count > 0 || secondTaskQueue.Count > 0)
                {
                    using (var tx = stateManager.CreateTransaction())
                    {
                        var dequeued = await firstTaskQueue.TryDequeueAsync(tx, cancellationToken);

                        if (!dequeued.HasValue)
                        {
                            dequeued = await secondTaskQueue.TryDequeueAsync(tx, cancellationToken);
                        }

                        await ProcessScrapingTask(
                            scrapingTask : dequeued.Value,
                            gitHubClient : gitHubClient, tx : tx,
                            firstTaskQueue : firstTaskQueue,
                            secondTaskQueue : secondTaskQueue,
                            userRepoSearchActorProvider : userRepoSearchActorProvider);

                        await tx.CommitAsync();
                    }
                }
                else
                {
                    await Task.Delay(Constants.EMPTY_DELAY, cancellationToken);
                }
            }
        }