Skip to content

Commit

Permalink
feat: cli添加policy重试机制
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz committed Jul 21, 2023
1 parent fd995e8 commit e2ffe35
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,38 @@ public AbpProManager(IOptions<AbpProCliOptions> options, IHttpClientFactory http
_cliOptions = options.Value;
}


/// <summary>
/// 获取最后一个版本
/// </summary>
public async Task<string> GetLatestSourceCodeVersionAsync()
{
return await Policy.Handle<Exception>().RetryAsync(5).ExecuteAsync(async () => await GetLatestVersionAsync());
}


/// <summary>
/// 检查版本是否存在
/// </summary>
public async Task<bool> CheckSourceCodeVersionAsync(string version)
{
return await Policy.Handle<Exception>().RetryAsync(5).ExecuteAsync(async () => await CheckVersionAsync(version));
}


/// <summary>
/// 下载源码
/// </summary>
public async Task<byte[]> DownloadAsync(string version, string outputPath)
{
return await Policy.Handle<Exception>().RetryAsync(5).ExecuteAsync(async () => await DownloadSourceCodeAsync(version, outputPath));
}


/// <summary>
/// 获取最后一个版本
/// </summary>
private async Task<string> GetLatestVersionAsync()
{
var github = new GitHubClient(new ProductHeaderValue(_cliOptions.RepositoryId))
{
Expand All @@ -31,7 +59,7 @@ public async Task<string> GetLatestSourceCodeVersionAsync()
/// <summary>
/// 检查版本是否存在
/// </summary>
public async Task<bool> CheckSourceCodeVersionAsync(string version)
private async Task<bool> CheckVersionAsync(string version)
{
try
{
Expand All @@ -49,11 +77,11 @@ public async Task<bool> CheckSourceCodeVersionAsync(string version)
return false;
}
}

/// <summary>
/// 下载源码
/// </summary>
public async Task<byte[]> DownloadAsync(string version, string outputPath)
private async Task<byte[]> DownloadSourceCodeAsync(string version, string outputPath)
{
var httpClient = _httpClientFactory.CreateClient();
var uri = new Uri($"https://github.com/{_cliOptions.Owner}/{_cliOptions.RepositoryId}/archive/refs/tags/{version}.zip");
Expand Down

0 comments on commit e2ffe35

Please sign in to comment.