예제 #1
0
        public Task RunAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(async() =>
            {
                try
                {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        var nextBlockToIndex = await _indexingService.GetNextBlockToIndexAsync(_startFrom);

                        if (nextBlockToIndex.HasValue)
                        {
                            await _indexingService.IndexBlockAsync(nextBlockToIndex.Value, Version);

                            await _logger.WriteInfoAsync
                            (
                                nameof(Erc20BalanceIndexingJob),
                                nameof(RunAsync),
                                "Block balances indexed",
                                $"Indexed balances of block {nextBlockToIndex}.",
                                DateTime.UtcNow
                            );
                        }
                        else
                        {
                            await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
                        }
                    }
                }
                catch (Exception e)
                {
                    await _logger.WriteErrorAsync
                    (
                        nameof(Erc20BalanceIndexingJob),
                        nameof(RunAsync),
                        "Indexing failed",
                        e,
                        DateTime.UtcNow
                    );

                    throw;
                }
            }, cancellationToken).Unwrap());
        }
예제 #2
0
        public Erc20BalanceIndexingActorDispatcher(
            IErc20BalanceIndexingService indexingService,
            ILog logger,
            ulong startFrom,
            IErc20BalanceIndexingActorFactory erc20BalanceIndexingActorFactory)
        {
            _indexingService = indexingService;
            _logger          = logger;
            _startFrom       = startFrom;

            _erc20BalanceIndexingActor = erc20BalanceIndexingActorFactory.Build(Context, "erc20BalanceIndexingActor");

            ReceiveAsync <Messages.Common.DoIterationMessage>(async(message) =>
            {
                var nextBlockToIndex = await _indexingService.GetNextBlockToIndexAsync(_startFrom);
                if (nextBlockToIndex.HasValue)
                {
                    await _erc20BalanceIndexingActor.Ask(
                        Messages.Erc20BalanceIndexingActor.CreateIndexBlockMessage(nextBlockToIndex.Value), TimeSpan.FromSeconds(30));
                }

                Self.Tell(Messages.Common.CreateDoIterationMessage());
            });
        }