Files
2025-11-20 09:51:24 +08:00

64 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FluentScheduler;
using Models;
using Services.Cache;
using Services.Manager;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TimingService
{
public class MyJob : IJob
{
public void Execute()
{
try
{
Logs.WriteTimingUDPLog("备份数据库~");
AuthorityDB dB = new AuthorityDB();
string sql = $@"declare @name varchar(50);
select @name = db_name() exec('BACKUP DATABASE ' + @name + ' TO DISK=''{AppDomain.CurrentDomain.BaseDirectory}App_Data\DataBackup\' + @name + '.bak'' with noformat ,init')";
//取消事务执行原始的sql
SqlSugarBase.Db.Ado.ExecuteCommand(sql);
dB.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, sql);
}
catch (Exception EX)
{
Logs.WriteTimingUDPLog("备份数据库~出错" + EX.ToString());
}
}
}
public class MyRegistry : Registry
{
//无参构造函数
public MyRegistry()
{
//每天2点
Schedule(() =>
{
if (!SyncHotelServer.SyncHotelGroups())
Logs.WriteTimingUDPLog("2:00执行定时任务--清除酒店失败~");
}).ToRunEvery(0).Days().At(2, 00);
//Schedule(() =>
//{
// SyncHotelServer.SyncAutho();
//}).ToRunEvery(0).Days().At(2, 05);
//每天2点
//Schedule<MyJob>().ToRunEvery(0).Days().At(2, 10);
}
/// <summary>
/// 同步与自动授权
/// </summary>
public static void GoWork()
{
JobManager.Initialize(new MyRegistry());
}
}
}