예제 #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (_proxySupplier == null)
            {
                throw new ArgumentException("None proxy supplier");
            }

            await Task.Factory.StartNew(async() =>
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    var failedNum = 0;
                    try
                    {
                        var proxies = await _proxySupplier.GetProxiesAsync();
                        await _pool.AddAsync(proxies);

                        await Task.Delay(30000, default);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Get proxies failed: {e}");
                        failedNum++;
                        if (failedNum > 5)
                        {
                            break;
                        }
                    }
                }
            }, stoppingToken);
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (_proxySupplier == null)
            {
                throw new ArgumentException("None proxy supplier");
            }

            await Task.Factory.StartNew(async() =>
            {
                var interval = _options.RefreshProxy * 1000;
                while (!stoppingToken.IsCancellationRequested)
                {
                    var failedNum = 0;
                    try
                    {
                        var proxies = await _proxySupplier.GetProxiesAsync();
                        var cnt     = await _pool.AddAsync(proxies);
                        if (cnt > 0)
                        {
                            _logger.LogInformation($"Find new {cnt} proxies");
                        }

                        await Task.Delay(interval, default);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Get proxies failed: {e}");
                        failedNum++;
                        if (failedNum > 5)
                        {
                            break;
                        }
                    }
                }
            }, stoppingToken);
        }