Пример #1
0
        public Erc20ContractIndexingActorDispatcher(
            IErc20ContractIndexingService indexingService,
            ILog logger,
            ulong startFrom,
            IErc20ContractIndexingActorFactory erc20ContractIndexingActorFactory)
        {
            _indexingService = indexingService;
            _logger          = logger;
            _startFrom       = startFrom;

            _erc20ContractIndexingActor = erc20ContractIndexingActorFactory.Build(Context, "erc20ContractIndexingActor");

            ReceiveAsync <Messages.Common.DoIterationMessage>(async(message) =>
            {
                var model = await _indexingService.GetNextContractToIndexAsync();
                if (model != null)
                {
                    await _erc20ContractIndexingActor.Ask(
                        Messages.Erc20ContractIndexingActor.CreateErc20ContractDeployedMessage(model), TimeSpan.FromSeconds(30));

                    Self.Tell(Messages.Common.CreateDoIterationMessage());
                }
                else
                {
                    Context.System.Scheduler.ScheduleTellOnce(TimeSpan.FromSeconds(10), Self, Messages.Common.CreateDoIterationMessage(), Self);
                }
            });
        }
Пример #2
0
        public Task RunAsync(CancellationToken cancellationToken)
        {
            return(Task.Factory.StartNew(async() =>
            {
                try
                {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        var contract = await _indexingService.GetNextContractToIndexAsync();

                        await RetryPolicy.ExecuteAsync(async() =>
                        {
                            await _indexingService.IndexContractAsync(contract);
                        }, 5, 100);

                        await _logger.WriteInfoAsync
                        (
                            nameof(Erc20ContractIndexingJob),
                            nameof(RunAsync),
                            "Contract indexed",
                            $"Indexed contract as address {contract.Address}.",
                            DateTime.UtcNow
                        );
                    }
                }
                catch (Exception e)
                {
                    await _logger.WriteErrorAsync
                    (
                        nameof(Erc20ContractIndexingJob),
                        nameof(RunAsync),
                        "Indexing failed",
                        e,
                        DateTime.UtcNow
                    );

                    throw;
                }
            }, cancellationToken).Unwrap());
        }