From c7b218f0f560bab4da0b0243d0e3ea18631405d3 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 14 Aug 2019 11:22:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Gitee=E6=8E=A5=E5=8F=A3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BD=BF=E7=94=A8=E5=B9=B6=E5=8F=91=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HealthChecks/GiteeHttpHealthCheck.cs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Bootstrap.Admin/HealthChecks/GiteeHttpHealthCheck.cs b/Bootstrap.Admin/HealthChecks/GiteeHttpHealthCheck.cs index 5bcd8ddf..37190086 100644 --- a/Bootstrap.Admin/HealthChecks/GiteeHttpHealthCheck.cs +++ b/Bootstrap.Admin/HealthChecks/GiteeHttpHealthCheck.cs @@ -38,24 +38,14 @@ namespace Bootstrap.Admin.HealthChecks var urls = new string[] { "Issues", "Pulls", "Releases", "Builds" }; var data = new Dictionary(); - urls.ToList().ForEach(url => + Task.WaitAll(urls.Select(url => Task.Run(async () => { var sw = Stopwatch.StartNew(); - try - { - var task = _client.GetStringAsync($"/api/Gitee/{url}"); - task.Wait(cancellationToken); - } - catch (Exception) - { - - } - finally - { - sw.Stop(); - data.Add(url, sw.Elapsed); - } - }); + Exception error = null; + var result = await _client.GetAsJsonAsync($"/api/Gitee/{url}", ex => error = ex, cancellationToken); + sw.Stop(); + data.Add(url, error == null ? $"{result} Elapsed: {sw.Elapsed}" : $"{result} Elapsed: {sw.Elapsed} Exception: {error}"); + })).ToArray()); return Task.FromResult(HealthCheckResult.Healthy("Ok", data)); } }