refactor: Gitee接口测试使用并发减少响应时间
This commit is contained in:
parent
f7c9a638ed
commit
c7b218f0f5
|
@ -38,24 +38,14 @@ namespace Bootstrap.Admin.HealthChecks
|
||||||
var urls = new string[] { "Issues", "Pulls", "Releases", "Builds" };
|
var urls = new string[] { "Issues", "Pulls", "Releases", "Builds" };
|
||||||
var data = new Dictionary<string, object>();
|
var data = new Dictionary<string, object>();
|
||||||
|
|
||||||
urls.ToList().ForEach(url =>
|
Task.WaitAll(urls.Select(url => Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
try
|
Exception error = null;
|
||||||
{
|
var result = await _client.GetAsJsonAsync<object>($"/api/Gitee/{url}", ex => error = ex, cancellationToken);
|
||||||
var task = _client.GetStringAsync($"/api/Gitee/{url}");
|
sw.Stop();
|
||||||
task.Wait(cancellationToken);
|
data.Add(url, error == null ? $"{result} Elapsed: {sw.Elapsed}" : $"{result} Elapsed: {sw.Elapsed} Exception: {error}");
|
||||||
}
|
})).ToArray());
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
sw.Stop();
|
|
||||||
data.Add(url, sw.Elapsed);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Task.FromResult(HealthCheckResult.Healthy("Ok", data));
|
return Task.FromResult(HealthCheckResult.Healthy("Ok", data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue