refactor: 后台任务日志使用 TaskLogController

#Comment
comment 原有 TaskController 负责任务持久化到数据库
This commit is contained in:
Argo Zhang 2019-07-08 09:05:59 +08:00
parent 6c90b13ba5
commit 63933f62fe
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 37 additions and 21 deletions

View File

@ -37,25 +37,6 @@ namespace Bootstrap.Admin.Controllers.Api
return true;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="hub"></param>
/// <returns></returns>
[HttpPut]
public bool Put([FromQuery]string name, [FromServices]IHubContext<SignalRHub> 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;
}
/// <summary>
///
/// </summary>

View File

@ -0,0 +1,34 @@
using Longbow.Tasks;
using Longbow.Web.SignalR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class TasksLogController : ControllerBase
{
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="hub"></param>
/// <returns></returns>
[HttpGet]
public bool Get([FromQuery]string name, [FromServices]IHubContext<SignalRHub> 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;
}
}
}

View File

@ -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)", "<span class='text-danger'>Run(Cancelled)</span>");
result = result.replace("Run(Success)", "<span class='text-success'>Run(Success)</span>");
this.append('<div>' + result + '</div>');
},
onclose: function (error) {