コード例 #1
0
ファイル: FetchService.cs プロジェクト: Caskia/Ambition
        public async Task FetchAsync(IRequestTask requestTask, CancellationToken cancellationToken)
        {
            while (true)
            {
                var result = await TryFetchAsync(requestTask, cancellationToken);

                if (result)
                {
                    break;
                }

                requestTask.LastTryTime = Clock.Now;
                requestTask.TryCount   += 1;
                requestTask.NextTryTime = requestTask.CalculateNextTryTime();
                _logger.LogInformation($"try to connect to uri[{requestTask.Uri}] at {requestTask.NextTryTime.ToString("yyyyMMddHHmmss")}");

                var now           = Clock.Now;
                var delayTimeSpan = new TimeSpan();
                if (requestTask.NextTryTime > now)
                {
                    delayTimeSpan = requestTask.NextTryTime - now;
                }
                await Task.Delay(delayTimeSpan, cancellationToken);

                _logger.LogInformation($"try to connect to uri[{requestTask.Uri}]");
            }
        }