예제 #1
0
        protected override async Task DoSomethingAsync(NpgsqlConnection connection, CancellationToken token)
        {
            uint lastBlockNum = 0;

            _blockIds.Clear();
            _container.Clear();
            bool isLastBlock;
            var  st = DateTime.Now;

            try
            {
                var count = BlockRange;

                _scraperState = await connection.GetServiceStateAsync <ScraperState>(ServiceId, token);

                await _blockMiningService.InitCashAsync(connection, _scraperState.BlockId, count, token);

                await _blockMiningService.StartAsync(_scraperState.BlockId + 1, _scraperState.BlockId + count, token);

                isLastBlock = count > _blockIds.Count;

                _temporaryLogManager.Add(new ScraperServiceTemporaryLog(st, _scraperState.BlockId, _blockIds.Count));
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                _temporaryLogManager.Add(new ScraperServiceTemporaryLog(e, st, _scraperState.BlockId));
                throw new Exception($"Last block num: {lastBlockNum}", e);
            }
            finally
            {
                if (!token.IsCancellationRequested && _scraperState != null)
                {
                    await BulkSaveAsync(connection, _container, _scraperState, token);
                }
            }

            if (isLastBlock)
            {
                //await connection.AddPrimaryKeyAndRelations(token);
                //await connection.AddPartitionsPrimaryKeyAndRelations(token);
                await connection.UpdateDelayedTokenAsync(token);

                await connection.UpdateDelayedTransferAsync(token);

                await connection.UpdateTransferInfo(token);

                await connection.CleanDelayedTransferAsync(token);

                await Task.Delay(TimeSpan.FromMinutes(5), token);
            }
        }