feat: 任务日志点击默认显示上一条执行结果

This commit is contained in:
Argo Zhang 2019-07-19 14:27:25 +08:00
parent 481310ca29
commit 7b3526d9c2
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 22 additions and 13 deletions

View File

@ -14,7 +14,7 @@ namespace Bootstrap.Admin.Controllers.Api
public class TasksLogController : ControllerBase public class TasksLogController : ControllerBase
{ {
/// <summary> /// <summary>
/// /// 任务管理页面日志按钮调用此方法
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="hub"></param> /// <param name="hub"></param>
@ -23,12 +23,16 @@ namespace Bootstrap.Admin.Controllers.Api
public bool Get([FromQuery]string name, [FromServices]IHubContext<SignalRHub> hub) public bool Get([FromQuery]string name, [FromServices]IHubContext<SignalRHub> hub)
{ {
var sche = TaskServicesManager.GetOrAdd(name); var sche = TaskServicesManager.GetOrAdd(name);
sche.Triggers.First().PulseCallback = async t => sche.Triggers.First().PulseCallback = t => SendTaskLog(sche, name, hub);
{ SendTaskLog(sche, name, hub);
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);
};
return true; return true;
} }
private void SendTaskLog(IScheduler sche, string name, IHubContext<SignalRHub> 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);
}
} }
} }

View File

@ -30,7 +30,7 @@
else if (value === "Timeout") { else if (value === "Timeout") {
content = $.format(template, 'warning', '超时'); content = $.format(template, 'warning', '超时');
} }
return content; return content;
}; };
$('.card-body table').lgbTable({ $('.card-body table').lgbTable({
@ -59,16 +59,12 @@
events: { events: {
'click .info': function (e, value, row, index) { 'click .info': function (e, value, row, index) {
$taskLogModelTitle.html(row.Name + ' - 任务日志窗口(最新50条)'); $taskLogModelTitle.html(row.Name + ' - 任务日志窗口(最新50条)');
$.bc({
url: 'api/TasksLog?name=' + row.Name
});
$('#dialogLog').modal('show').on('hide.bs.modal', function () { $('#dialogLog').modal('show').on('hide.bs.modal', function () {
// close hub // close hub
if ($taskMsg.hub) $taskMsg.hub.stop(); if ($taskMsg.hub) $taskMsg.hub.stop();
$taskMsg.html('<div></div>'); $taskMsg.html('<div></div>');
}); });
// var lastMsg = "";
// open hub // open hub
$taskMsg.notifi({ $taskMsg.notifi({
url: 'NotiHub', url: 'NotiHub',
@ -82,13 +78,20 @@
if (data.name !== row.Name) return; if (data.name !== row.Name) return;
result = data.msg; result = data.msg;
result = result.replace("Run(Cancelled)", "<span class='text-danger'>Run(Cancelled)</span>"); result = result.replace("Run(Cancelled)", "<span class='text-info'>Run(Cancelled)</span>");
result = result.replace("Run(Success)", "<span class='text-success'>Run(Success)</span>"); result = result.replace("Run(Success)", "<span class='text-success'>Run(Success)</span>");
result = result.replace("Run(Error)", "<span class='text-danger'>Run(Error)</span>");
result = result.replace("Run(Timeout)", "<span class='text-warning'>Run(Timeout)</span>");
content.append('<div>' + result + '</div>'); content.append('<div>' + result + '</div>');
// auto scroll // auto scroll
if ($autoScroll.find('i').hasClass(check[0])) this.scrollTop(content.height()); if ($autoScroll.find('i').hasClass(check[0])) this.scrollTop(content.height());
}, },
invoke: function () {
$.bc({
url: 'api/TasksLog?name=' + row.Name
});
},
onclose: function (error) { onclose: function (error) {
console.log(error); console.log(error);
} }

View File

@ -461,7 +461,9 @@
// 连接成功 // 连接成功
// invoke 为 调用服务端方法 // invoke 为 调用服务端方法
// invoke: function (connection) { return connection.invoke('RetrieveDashboard'); } // 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; this.hub = connection;
return this; return this;