2023-12-08 09:21:55 +08:00

40 lines
1.2 KiB
C#
Raw 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 Infrastructure.Attribute;
using Quartz;
using SqlSugar.IOC;
using System.Threading.Tasks;
using ZR.Model.System;
namespace ZR.Tasks.TaskScheduler
{
/// <summary>
/// 定时任务测试
/// 使用如下注册后TaskExtensions里面不用再注册了
/// </summary>
[AppService(ServiceType = typeof(Job_SyncTest), ServiceLifetime = LifeTime.Scoped)]
public class Job_SyncTest : JobBase, IJob
{
//private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, Run);
}
/// <summary>
/// 任务使用中注意所有方法都需要使用异步并且不能少了await
/// </summary>
/// <returns></returns>
public async Task Run()
{
await Task.Delay(1);
//TODO 业务逻辑
var db = DbScoped.SugarScope;
var info = await db.Queryable<SysDept>().FirstAsync();
//其他库操作
//var db2 = DbScoped.SugarScope.GetConnectionScope(2);
System.Console.WriteLine("job test");
}
}
}