Skip to content

Commit

Permalink
CLI HttpClient timeout increased. closes #8327
Browse files Browse the repository at this point in the history
  • Loading branch information
ebicoglu committed Apr 2, 2021
1 parent 592c9d1 commit 48c5262
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Volo.Abp.Cli.Http
{
public class CliHttpClientFactory : ISingletonDependency
{
public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1);
public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(2);

private readonly IHttpClientFactory _clientFactory;
private readonly ICancellationTokenProvider _cancellationTokenProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public async Task<TemplateFile> GetAsync(
if (!string.IsNullOrWhiteSpace(templateSource) && !IsNetworkSource(templateSource))
{
Logger.LogInformation("Using local " + type + ": " + name + ", version: " + version);
return new TemplateFile(File.ReadAllBytes(Path.Combine(templateSource, name + "-" + version + ".zip")), version, latestVersion, nugetVersion);
return new TemplateFile(File.ReadAllBytes(Path.Combine(templateSource, name + "-" + version + ".zip")),
version, latestVersion, nugetVersion);
}

var localCacheFile = Path.Combine(CliPaths.TemplateCache, name.Replace("/",".") + "-" + version + ".zip");
var localCacheFile = Path.Combine(CliPaths.TemplateCache, name.Replace("/", ".") + "-" + version + ".zip");

#if DEBUG
if (File.Exists(localCacheFile))
Expand Down Expand Up @@ -127,7 +128,8 @@ public async Task<TemplateFile> GetAsync(
return new TemplateFile(fileContent, version, latestVersion, nugetVersion);
}

private async Task<string> GetLatestSourceCodeVersionAsync(string name, string type, string url = null, bool includePreReleases = false)
private async Task<string> GetLatestSourceCodeVersionAsync(string name, string type, string url = null,
bool includePreReleases = false)
{
if (url == null)
{
Expand All @@ -138,12 +140,14 @@ private async Task<string> GetLatestSourceCodeVersionAsync(string name, string t
{
var client = _cliHttpClientFactory.CreateClient();
var stringContent = new StringContent(
JsonSerializer.Serialize(new GetLatestSourceCodeVersionDto { Name = name, IncludePreReleases = includePreReleases }),
JsonSerializer.Serialize(new GetLatestSourceCodeVersionDto
{Name = name, IncludePreReleases = includePreReleases}),
Encoding.UTF8,
MimeTypes.Application.Json
);

using (var response = await client.PostAsync(url, stringContent, _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
using (var response = await client.PostAsync(url, stringContent,
_cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
{
await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
var result = await response.Content.ReadAsStringAsync();
Expand All @@ -170,12 +174,13 @@ private async Task<string> GetTemplateNugetVersionAsync(string name, string type
var client = _cliHttpClientFactory.CreateClient();

var stringContent = new StringContent(
JsonSerializer.Serialize(new GetTemplateNugetVersionDto { Name = name, Version = version }),
JsonSerializer.Serialize(new GetTemplateNugetVersionDto {Name = name, Version = version}),
Encoding.UTF8,
MimeTypes.Application.Json
);

using (var response = await client.PostAsync(url, stringContent, _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
using (var response = await client.PostAsync(url, stringContent,
_cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
{
await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
var result = await response.Content.ReadAsStringAsync();
Expand All @@ -196,19 +201,20 @@ private async Task<byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInpu

try
{
var client = _cliHttpClientFactory.CreateClient();
var client = _cliHttpClientFactory.CreateClient(timeout: TimeSpan.FromMinutes(5));

if (input.TemplateSource.IsNullOrWhiteSpace())
{
responseMessage = await client.PostAsync(
url,
new StringContent(JsonSerializer.Serialize(input), Encoding.UTF8, MimeTypes.Application.Json),
_cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))
_cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))
);
}
else
{
responseMessage = await client.GetAsync(input.TemplateSource, _cliHttpClientFactory.GetCancellationToken());
responseMessage = await client.GetAsync(input.TemplateSource,
_cliHttpClientFactory.GetCancellationToken());
}

await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage);
Expand All @@ -219,7 +225,8 @@ private async Task<byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInpu
}
catch (Exception ex)
{
Console.WriteLine("Error occured while downloading source-code from {0} : {1}{2}{3}", url, responseMessage?.ToString(), Environment.NewLine, ex.Message);
Console.WriteLine("Error occured while downloading source-code from {0} : {1}{2}{3}", url,
responseMessage?.ToString(), Environment.NewLine, ex.Message);
throw;
}
}
Expand All @@ -239,7 +246,8 @@ private static bool IsNetworkSource(string source)
stringBuilder.AppendLine(cacheFile);
}

var matches = Regex.Matches(stringBuilder.ToString(), $"({AppTemplate.TemplateName}|{AppProTemplate.TemplateName}|{ModuleTemplate.TemplateName}|{ModuleProTemplate.TemplateName}|{ConsoleTemplate.TemplateName}|{WpfTemplate.TemplateName})-(.+).zip");
var matches = Regex.Matches(stringBuilder.ToString(),
$"({AppTemplate.TemplateName}|{AppProTemplate.TemplateName}|{ModuleTemplate.TemplateName}|{ModuleProTemplate.TemplateName}|{ConsoleTemplate.TemplateName}|{WpfTemplate.TemplateName})-(.+).zip");
foreach (Match match in matches)
{
templateList.Add((match.Groups[1].Value, match.Groups[2].Value));
Expand Down Expand Up @@ -282,4 +290,4 @@ public class GetVersionResultDto
public string Version { get; set; }
}
}
}
}

0 comments on commit 48c5262

Please sign in to comment.