refactor: 任务管理整理排版增加禁用任务示例

This commit is contained in:
Argo Zhang 2019-09-10 16:02:49 +08:00
parent 17d5139608
commit 766acbfca9
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 6 additions and 2 deletions

View File

@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api
private async Task SendTaskLog(IScheduler sche, string name, IHubContext<TaskLogHub> hub)
{
var t = sche.Triggers.First();
var result = $"{{\"name\": \"{name}\", \"msg\": \"Trigger({t.GetType().Name}) LastRuntime: {sche.LastRuntime} Run({t.LastResult}) NextRuntime: {sche.NextRuntime} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}";
var result = $"{{\"name\": \"{name}\", \"msg\": \"Trigger({t.GetType().Name}) LastRuntime: {sche.LastRuntime?.ToString() ?? "none"} Run({t.LastResult}) NextRuntime: {sche.NextRuntime?.ToString() ?? "none"} Elapsed: {t.LastRunElapsedTime.Seconds}s\"}}";
await hub.SendTaskLog(result);
}
}

View File

@ -46,6 +46,9 @@ namespace Microsoft.Extensions.DependencyInjection
// 此处代码可注释掉
TaskServicesManager.GetOrAdd("故障任务", token => throw new Exception("故障任务"));
TaskServicesManager.GetOrAdd("取消任务", token => Task.Delay(1000)).Triggers.First().Enabled = false;
// 创建任务并禁用
TaskServicesManager.GetOrAdd("禁用任务", token => Task.Delay(1000)).Status = SchedulerStatus.Disabled;
});
}
}

View File

@ -40,9 +40,10 @@
<p>3. Cron 表达式任务 (间隔 5 秒循环执行任务)</p>
<p>
<code>
TaskServicesManager.GetOrAdd("Cron表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
</code>
</p>
<p class="mb-0">开源地址: <a href="https://gitee.com/LongbowGroup/Longbow.Tasks" target="_blank">https://gitee.com/LongbowGroup/Longbow.Tasks</a></p>
</div>
</div>
}