using System.Net; using Core; using FluentScheduler; using Interface.Jobs; namespace Service.Jobs; public class ShutdownRegistry : Registry, IShutdownRegistry { public ShutdownRegistry() { Schedule(Job).ToRunEvery(1).Days().At(23, 30); } public async void Job() { try { await JobExecute(); } catch (Exception e) { Console.WriteLine(e); await WxNotify.SendCommonAsync($"ShutdownRegistry.Job() error: {e}"); } } private async Task JobExecute() { var command = "shutdown 9"; var (responseCode, msg) = await Command.ExecAsync(command); var wxMsg = $@" # 定时关机指令执行 > 执行结果:{responseCode} > 执行消息:{msg} 如需取消关机请点击:[取消关机](http://suncheng.online:35642/api/JobTrigger/CancelShutdown) "; await WxNotify.SendCommonAsync(wxMsg); if (responseCode == HttpStatusCode.OK) { // 每三分钟提醒一次 _ = Task.Delay(3 * 60 * 1000).ContinueWith(async _ => await WxNotify.SendCommonAsync(wxMsg)); } } public async Task CancelShutdown() { var command = "shutdown -c"; var (responseCode, _) = await Command.ExecAsync(command); await WxNotify.SendCommonAsync($"取消关机指令执行完成 {responseCode}"); } }