From 766acbfca9c1f80b7222a6752fecaf6bdfae3d37 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 10 Sep 2019 16:02:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=BB=E5=8A=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=95=B4=E7=90=86=E6=8E=92=E7=89=88=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E4=BB=BB=E5=8A=A1=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Admin/Controllers/Api/TasksLogController.cs | 2 +- src/admin/Bootstrap.Admin/Tasks/TasksExtensions.cs | 3 +++ src/admin/Bootstrap.Admin/Views/Admin/Tasks.cshtml | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Controllers/Api/TasksLogController.cs b/src/admin/Bootstrap.Admin/Controllers/Api/TasksLogController.cs index 85ce98a3..533e43ba 100644 --- a/src/admin/Bootstrap.Admin/Controllers/Api/TasksLogController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/Api/TasksLogController.cs @@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api private async Task SendTaskLog(IScheduler sche, string name, IHubContext hub) { var t = sche.Triggers.First(); - var result = $"{{\"name\": \"{name}\", \"msg\": \"Trigger({t.GetType().Name}) LastRuntime: {sche.LastRuntime} Run({t.LastResult}) NextRuntime: {sche.NextRuntime} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}"; + var result = $"{{\"name\": \"{name}\", \"msg\": \"Trigger({t.GetType().Name}) LastRuntime: {sche.LastRuntime?.ToString() ?? "none"} Run({t.LastResult}) NextRuntime: {sche.NextRuntime?.ToString() ?? "none"} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}"; await hub.SendTaskLog(result); } } diff --git a/src/admin/Bootstrap.Admin/Tasks/TasksExtensions.cs b/src/admin/Bootstrap.Admin/Tasks/TasksExtensions.cs index 5dab2e4d..53cc1a66 100644 --- a/src/admin/Bootstrap.Admin/Tasks/TasksExtensions.cs +++ b/src/admin/Bootstrap.Admin/Tasks/TasksExtensions.cs @@ -46,6 +46,9 @@ namespace Microsoft.Extensions.DependencyInjection // 此处代码可注释掉 TaskServicesManager.GetOrAdd("故障任务", token => throw new Exception("故障任务")); TaskServicesManager.GetOrAdd("取消任务", token => Task.Delay(1000)).Triggers.First().Enabled = false; + + // 创建任务并禁用 + TaskServicesManager.GetOrAdd("禁用任务", token => Task.Delay(1000)).Status = SchedulerStatus.Disabled; }); } } diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Tasks.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Tasks.cshtml index e1d10b56..7b32d715 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Tasks.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Tasks.cshtml @@ -40,9 +40,10 @@

3. Cron 表达式任务 (间隔 5 秒循环执行任务)

- TaskServicesManager.GetOrAdd("Cron表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *")); + TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));

+

开源地址: https://gitee.com/LongbowGroup/Longbow.Tasks

}