示例#1
0
        public Erc20BalanceIndexingActor(
            IErc20BalanceIndexingService indexingService,
            ILog logger,
            ulong startFrom)
        {
            _indexingService = indexingService;
            _logger          = logger;
            _startFrom       = startFrom;

            ReceiveAsync <Messages.Erc20BalanceIndexingActor.IndexBlockMessage>(async(message) =>
            {
                var sender      = Sender;
                var blockNumber = message.BlockNumber;
                await _indexingService.IndexBlockAsync(blockNumber, Version);

                await _logger.WriteInfoAsync
                (
                    nameof(Erc20BalanceIndexingJob),
                    nameof(ReceiveAsync),
                    "Block balances indexed",
                    $"Indexed balances of block {blockNumber}.",
                    DateTime.UtcNow
                );

                sender.Tell(new Success(true));
            });
        }
示例#2
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());
        }