public async Task Execute()
        {
            await _logger.WriteInfoAsync("PoolRenewJob", "Execute", "", "PoolRenewJob has been started ", DateTime.UtcNow);

            await _coinRepository.ProcessAllAsync(async (coins) =>
            {
                foreach (var coin in coins)
                {
                    try
                    {
                        string coinPoolQueueName = QueueHelper.GenerateQueueNameForContractPool(coin.AdapterAddress);
                        ITransferContractQueueService transferContractQueueService =
                            _transferContractQueueServiceFactory.Get(coinPoolQueueName);
                        var count = await transferContractQueueService.Count();

                        for (int i = 0; i < count; i++)
                        {
                            var contract = await transferContractQueueService.GetContract();
                            if (contract == null)
                            {
                                return;
                            }
                            await transferContractQueueService.PushContract(contract);
                        }

                        await _logger.WriteInfoAsync("PoolRenewJob", "Execute", "", $"PoolRenewJob has been finished for {count} contracts in {coinPoolQueueName} ", DateTime.UtcNow);
                    }
                    catch (Exception e)
                    {
                        await _logger.WriteErrorAsync("PoolRenewJob", "Execute", "", e);
                    }
                }
            });
        }
Example #2
0
        public async Task Execute(ICoin coin)
        {
            await InternalBalanceCheck();

            string coinPoolQueueName = QueueHelper.GenerateQueueNameForContractPool(coin.AdapterAddress);
            ITransferContractQueueService transferContractQueueService =
                _transferContractQueueServiceFactory.Get(coinPoolQueueName);

            int currentCount = await transferContractQueueService.Count();

            if (currentCount < _settings.MinContractPoolLength)
            {
                while (currentCount < _settings.MaxContractPoolLength)
                {
                    await InternalBalanceCheck();

                    List <string> trHashes = new List <string>(_settings.ContractsPerRequest);

                    for (int i = 0; i < _settings.ContractsPerRequest; i++)
                    {
                        var transferContractTrHash =
                            await _transferContractService.CreateTransferContractTrHashWithoutUser(coin.AdapterAddress);

                        trHashes.Add(transferContractTrHash);
                    }

                    IEnumerable <string> contractAddresses = await _contractService.GetContractsAddresses(trHashes);

                    List <Task> contractPushTasks = new List <Task>();

                    foreach (var address in contractAddresses)
                    {
                        await transferContractQueueService.PushContract(new TransferContract()
                        {
                            CoinAdapterAddress   = coin.AdapterAddress,
                            ContainsEth          = coin.ContainsEth,
                            ContractAddress      = address,
                            ExternalTokenAddress = coin.ExternalTokenAddress,
                        });
                    }

                    currentCount += _settings.ContractsPerRequest;
                }
            }
        }