diff --git a/Bootstrap.Admin/Controllers/Api/TasksLogController.cs b/Bootstrap.Admin/Controllers/Api/TasksLogController.cs index 400724c3..cb4f90cb 100644 --- a/Bootstrap.Admin/Controllers/Api/TasksLogController.cs +++ b/Bootstrap.Admin/Controllers/Api/TasksLogController.cs @@ -14,7 +14,7 @@ namespace Bootstrap.Admin.Controllers.Api public class TasksLogController : ControllerBase { /// - /// + /// 任务管理页面日志按钮调用此方法 /// /// /// @@ -23,12 +23,16 @@ namespace Bootstrap.Admin.Controllers.Api public bool Get([FromQuery]string name, [FromServices]IHubContext hub) { var sche = TaskServicesManager.GetOrAdd(name); - sche.Triggers.First().PulseCallback = async t => - { - var result = $"{{\"name\": \"{name}\", \"msg\": \"{sche.LastRuntime}: Trigger({t.GetType().Name}) Run({t.LastResult}) NextRuntime: {sche.NextRuntime} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}"; - await SignalRManager.SendTaskLog(hub.Clients.All, result); - }; + sche.Triggers.First().PulseCallback = t => SendTaskLog(sche, name, hub); + SendTaskLog(sche, name, hub); return true; } + + private void SendTaskLog(IScheduler sche, string name, IHubContext hub) + { + var t = sche.Triggers.First(); + var result = $"{{\"name\": \"{name}\", \"msg\": \"{sche.LastRuntime}: Trigger({t.GetType().Name}) Run({t.LastResult}) NextRuntime: {sche.NextRuntime} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}"; + SignalRManager.SendTaskLog(hub.Clients.All, result).ConfigureAwait(false); + } } } diff --git a/Bootstrap.Admin/wwwroot/js/tasks.js b/Bootstrap.Admin/wwwroot/js/tasks.js index 2d186606..fd5bcb3f 100644 --- a/Bootstrap.Admin/wwwroot/js/tasks.js +++ b/Bootstrap.Admin/wwwroot/js/tasks.js @@ -30,7 +30,7 @@ else if (value === "Timeout") { content = $.format(template, 'warning', '超时'); } - return content; + return content; }; $('.card-body table').lgbTable({ @@ -59,16 +59,12 @@ events: { 'click .info': function (e, value, row, index) { $taskLogModelTitle.html(row.Name + ' - 任务日志窗口(最新50条)'); - $.bc({ - url: 'api/TasksLog?name=' + row.Name - }); $('#dialogLog').modal('show').on('hide.bs.modal', function () { // close hub if ($taskMsg.hub) $taskMsg.hub.stop(); $taskMsg.html('
'); }); - // var lastMsg = ""; // open hub $taskMsg.notifi({ url: 'NotiHub', @@ -82,13 +78,20 @@ if (data.name !== row.Name) return; result = data.msg; - result = result.replace("Run(Cancelled)", "Run(Cancelled)"); + result = result.replace("Run(Cancelled)", "Run(Cancelled)"); result = result.replace("Run(Success)", "Run(Success)"); + result = result.replace("Run(Error)", "Run(Error)"); + result = result.replace("Run(Timeout)", "Run(Timeout)"); content.append('
' + result + '
'); // auto scroll if ($autoScroll.find('i').hasClass(check[0])) this.scrollTop(content.height()); }, + invoke: function () { + $.bc({ + url: 'api/TasksLog?name=' + row.Name + }); + }, onclose: function (error) { console.log(error); } diff --git a/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js b/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js index 7c1c05ea..eca76277 100644 --- a/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js +++ b/Bootstrap.Admin/wwwroot/lib/longbow/longbow.common.js @@ -461,7 +461,9 @@ // 连接成功 // invoke 为 调用服务端方法 // invoke: function (connection) { return connection.invoke('RetrieveDashboard'); } - if (op.invoke) op.invoke(connection).then(function (result) { console.log(result); }).catch(function (err) { console.error(err.toString()); }); + if (!op.invoke) return; + var executor = op.invoke(connection); + if (typeof executor === "object" && $.isFunction(executor.then)) executor.then(function (result) { console.log(result); }).catch(function (err) { console.error(err.toString()); }); }); this.hub = connection; return this;