您的位置:首页 > 文旅 > 美景 > 嘉峪关网站seo_庆阳市门户网_网络营销概念_网络推广专员所需知识

嘉峪关网站seo_庆阳市门户网_网络营销概念_网络推广专员所需知识

2024/12/23 11:34:40 来源:https://blog.csdn.net/qq_38313984/article/details/143435187  浏览:    关键词:嘉峪关网站seo_庆阳市门户网_网络营销概念_网络推广专员所需知识
嘉峪关网站seo_庆阳市门户网_网络营销概念_网络推广专员所需知识

1.nuget安装Quartz.AspNetCore

2.startup的ConfigureServices方法中增加注入

services.AddQuartz(q =>{q.UseMicrosoftDependencyInjectionJobFactory();//是否开启定时补传打卡记录if (Common.Const.IsOpenPostRecordInfosSyn=="1"){var jobKey = new JobKey("PostRecordInfosJob");q.AddJob<App_Code.QuartzJob.PostRecordInfosJob>(opts => opts.WithIdentity(jobKey));q.AddTrigger(opts => opts.ForJob(jobKey).WithIdentity("PostRecordInfosJob-trigger")//每分钟.WithCronSchedule("0 * * * * ?"));}//是否开启定时同步部门、员工信息if (Common.Const.IsOpenBaseInfoSyn == "1"){var jobKey = new JobKey("BaseInfoSynJob");q.AddJob<App_Code.QuartzJob.BaseInfoSynJob>(opts => opts.WithIdentity(jobKey));q.AddTrigger(opts => opts.ForJob(jobKey).WithIdentity("BaseInfoSyn-trigger")//每小时.WithCronSchedule("0 0 * * * ?"));}//是否开启定时同步设备状态if (Common.Const.IsOpenDeviceStateSyn == "1"){var jobKey = new JobKey("DeviceStateSynJob");q.AddJob<App_Code.QuartzJob.DeviceStateSynJob>(opts => opts.WithIdentity(jobKey));q.AddTrigger(opts => opts.ForJob(jobKey).WithIdentity("DeviceStateSynJob-trigger")//每分钟.WithCronSchedule("0 * * * * ?"));}});// ASP.NET Core hostingservices.AddQuartzServer(options =>{// when shutting down we want jobs to complete gracefullyoptions.WaitForJobsToComplete = true;                });

 3.实现job接口

 [DisallowConcurrentExecution]public class PostRecordInfosJob : IJob{private readonly IConfiguration _config;private readonly IHttpClientFactory _factory;private readonly IFreeSql _freeSql; public PostRecordInfosJob(IConfiguration config,IHttpClientFactory factory, IFreeSql freeSql){_config = config;_factory = factory;_freeSql = freeSql;}/// <summary>/// 补传打卡记录(补传记录每天12点进行一次)/// </summary>//对于耗时任务,需要上一次执行完成后,才执行下次任务,覆盖之前设置的执行周期 public async Task Execute(IJobExecutionContext context){try{postRecordInfos();}catch (Exception ex){Common.LogHelper.Error(Common.LogHelper.GetMethodInfo(), ex.ToString(), XHEnum.LogType.异常Error, ex);}}}

 部署到服务器是需要注意引入这四个dll

System.Configuration.ConfigurationManager.dll 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com