From 63933f62fe196aea94ebc26df64c8916a9fe7bb5 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 8 Jul 2019 09:05:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=90=8E=E5=8F=B0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=A5=E5=BF=97=E4=BD=BF=E7=94=A8=20TaskLogControll?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment comment 原有 TaskController 负责任务持久化到数据库 --- .../Controllers/Api/TasksController.cs | 19 ----------- .../Controllers/Api/TasksLogController.cs | 34 +++++++++++++++++++ Bootstrap.Admin/wwwroot/js/tasks.js | 5 +-- 3 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 Bootstrap.Admin/Controllers/Api/TasksLogController.cs diff --git a/Bootstrap.Admin/Controllers/Api/TasksController.cs b/Bootstrap.Admin/Controllers/Api/TasksController.cs index 29bc80be..f68990b7 100644 --- a/Bootstrap.Admin/Controllers/Api/TasksController.cs +++ b/Bootstrap.Admin/Controllers/Api/TasksController.cs @@ -37,25 +37,6 @@ namespace Bootstrap.Admin.Controllers.Api return true; } - /// - /// - /// - /// - /// - /// - [HttpPut] - public bool Put([FromQuery]string name, [FromServices]IHubContext hub) - { - var sche = TaskServicesManager.GetOrAdd(name); - sche.Triggers[0].RegisterPulseCallback(async t => - { - var success = t.Cancelled ? "Cancelled" : "Success"; - var result = $"{t.Scheduler.LastRuntime.Value.DateTime}: Trigger({t.GetType().Name}) Run({success}) NextRuntime: {t.NextRuntime.Value.DateTime} Elapsed: {t.LastRunElapsedTime.Seconds}s"; - await SignalRManager.SendTaskLog(hub.Clients.All, result); - }); - return true; - } - /// /// /// diff --git a/Bootstrap.Admin/Controllers/Api/TasksLogController.cs b/Bootstrap.Admin/Controllers/Api/TasksLogController.cs new file mode 100644 index 00000000..5c504dda --- /dev/null +++ b/Bootstrap.Admin/Controllers/Api/TasksLogController.cs @@ -0,0 +1,34 @@ +using Longbow.Tasks; +using Longbow.Web.SignalR; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; + +namespace Bootstrap.Admin.Controllers.Api +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class TasksLogController : ControllerBase + { + /// + /// + /// + /// + /// + /// + [HttpGet] + public bool Get([FromQuery]string name, [FromServices]IHubContext hub) + { + var sche = TaskServicesManager.GetOrAdd(name); + sche.Triggers[0].RegisterPulseCallback(async t => + { + var success = t.Cancelled ? "Cancelled" : "Success"; + var result = $"{t.Scheduler.LastRuntime.Value.DateTime}: Trigger({t.GetType().Name}) Run({success}) NextRuntime: {t.NextRuntime.Value.DateTime} Elapsed: {t.LastRunElapsedTime.Seconds}s"; + await SignalRManager.SendTaskLog(hub.Clients.All, result); + }); + return true; + } + } +} diff --git a/Bootstrap.Admin/wwwroot/js/tasks.js b/Bootstrap.Admin/wwwroot/js/tasks.js index 315ba288..9fa098dd 100644 --- a/Bootstrap.Admin/wwwroot/js/tasks.js +++ b/Bootstrap.Admin/wwwroot/js/tasks.js @@ -48,8 +48,7 @@ 'click .info': function (e, value, row, index) { $taskLogModelTitle.html(row.Name + ' - 任务日志窗口(最新50条)'); $.bc({ - url: 'api/Tasks?name=' + row.Name, - method: 'put' + url: 'api/TasksLog?name=' + row.Name }); $('#dialogLog').modal('show').on('hide.bs.modal', function () { // close hub @@ -68,6 +67,8 @@ while (this.children().length > 50) { this.children().first().remove(); } + result = result.replace("Run(Cancelled)", "Run(Cancelled)"); + result = result.replace("Run(Success)", "Run(Success)"); this.append('
' + result + '
'); }, onclose: function (error) {