feat: 增加任务日志功能
This commit is contained in:
parent
92e3aa4c35
commit
188470bc1d
|
@ -0,0 +1 @@
|
|||
<BootstrapBlazor.Components.Console Items="@Messages" Height="280" ShowAutoScroll="true" />
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using BootstrapAdmin.Web.Models;
|
||||
using Longbow.Tasks;
|
||||
|
||||
namespace BootstrapAdmin.Web.Components;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class TaskInfo
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
[NotNull]
|
||||
[EditorRequired]
|
||||
public TasksModel? Model { get; set; }
|
||||
|
||||
private List<ConsoleMessageItem> Messages { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="firstRender"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
var sche = TaskServicesManager.Get(Model.Name);
|
||||
if (sche != null)
|
||||
{
|
||||
sche.Triggers.First().PulseCallback = async t => await DispatchMessage(t);
|
||||
await DispatchMessage(sche.Triggers.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DispatchMessage(ITrigger trigger)
|
||||
{
|
||||
var message = $"Trigger({trigger.GetType().Name}) LastRuntime: {trigger.LastRuntime} Run({trigger.LastResult}) NextRuntime: {trigger.NextRuntime} Elapsed: {trigger.LastRunElapsedTime.TotalSeconds}";
|
||||
Messages.Add(new ConsoleMessageItem()
|
||||
{
|
||||
Message = message
|
||||
});
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using BootstrapAdmin.Web.Components;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
using BootstrapAdmin.Web.Models;
|
||||
|
@ -32,6 +33,10 @@ public partial class Tasks
|
|||
[NotNull]
|
||||
private IDict? DictService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private DialogService? DialogService { get; set; }
|
||||
|
||||
private bool IsDemo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -157,9 +162,18 @@ public partial class Tasks
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static Task OnLog(TasksModel model)
|
||||
private async Task OnLog(TasksModel model)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
var option = new DialogOption()
|
||||
{
|
||||
Class = "task-info",
|
||||
Title = $"{model.Name} - 日志窗口(最新50条)",
|
||||
Component = BootstrapDynamicComponent.CreateComponent<TaskInfo>(new Dictionary<string, object?>
|
||||
{
|
||||
[nameof(TaskInfo.Model)] = model
|
||||
})
|
||||
};
|
||||
await DialogService.Show(option);
|
||||
}
|
||||
|
||||
private static bool OnCheckTaskStatus(TasksModel model) => model.Status != SchedulerStatus.Disabled;
|
||||
|
|
Loading…
Reference in New Issue