////创建调度单元
//Task<IScheduler> tsk = StdSchedulerFactory.GetDefaultScheduler();
//IScheduler scheduler = tsk.Result;
////2.创建一个具体的作业即job (具体的job需要单独在一个文件中执行)
//IJobDetail job = JobBuilder.Create<ResourceDataJob>().WithIdentity("完成").Build();
////3.创建并配置一个触发器即trigger 1分钟执行一次i
//ITrigger _CronTrigger = TriggerBuilder.Create()
// .WithIdentity("定时确认")
// .WithCronSchedule("0/5 * * * * ?") //秒 分 时 某一天 月 周 年(可选参数)
// .Build()
// as ITrigger;
////4.将job和trigger加入到作业调度池中
//scheduler.ScheduleJob(job, _CronTrigger);
//// 创建具体的作业:SynchronousDataJob
//IJobDetail synchronousDataJob = JobBuilder.Create<synchronousDataJob>()
// .WithIdentity("每天24点执行")
// .Build();
//// 创建 SynchronousDataJob 对应的触发器,每天的 24:00 触发一次
//ITrigger synchronousDataTrigger = TriggerBuilder.Create()
// .WithIdentity("定时执行")
// .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 0))
// .Build();
//// 将 SynchronousDataJob 和触发器加入到作业调度池中
//scheduler.ScheduleJob(synchronousDataJob, synchronousDataTrigger);
////5.开启调度
//scheduler.Start();
-----------------------------------------------------------------------------------------------------------------
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SHWY.SourceData.Service.Business.Global.Resource
{
/// <summary>
/// 调度中心
/// </summary>
public class ScheduleManage
{
/// <summary>
/// 调度方法
/// 调度方法
/// </summary>
public static void Schedule()
{
// 创建第一个调度器
IScheduler scheduler1 = StdSchedulerFactory.GetDefaultScheduler().Result;
// 创建第一个作业和触发器
IJobDetail job1 = JobBuilder.Create<ResourceDataJob>()
.WithIdentity("完成")
.Build();
ITrigger trigger1 = TriggerBuilder.Create()
.WithIdentity("定时确认")
.WithCronSchedule("0/5 * * * * ?")
.Build();
scheduler1.ScheduleJob(job1, trigger1);
// 开启第一个调度器
scheduler1.Start();
// 创建第二个调度器
IScheduler scheduler2 = StdSchedulerFactory.GetDefaultScheduler().Result;
// 创建第二个作业和触发器
IJobDetail job2 = JobBuilder.Create<synchronousDataJob>()
.WithIdentity("每天24点执行")
.Build();
ITrigger trigger2 = TriggerBuilder.Create()
.WithIdentity("定时执行")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 0))
.Build();
scheduler2.ScheduleJob(job2, trigger2);
// 开启第二个调度器
scheduler2.Start();
}
}
}
----------------------------------------------------------------------------------------------------------------------
using Quartz;
using SHWY.SourceData.Enties.DbModels.shwy_base;
using SHWY.SourceData.IService.Business.Global.FileManage;
using SHWY.SourceData.IService.Business.Global.PlanReport;
using SHWY.SourceData.IService.Business.Global.Resource;
using SHWY.SourceData.Service.Business.Global.FileManage;
using SHWY.SourceData.Service.Business.Global.MiddleGround;
using SHWY.SourceData.Service.Config;
using SqlSugar.DBCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHWY.SourceData.Service.Business.Global.Resource
{
/// <summary>
/// 监控数据job
/// </summary>
public class ResourceDataJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() => {
string errormsg = null;
MiddleGroundService service = new MiddleGroundService();
// service.executeLogSchedaulTask(ref errormsg);
service.RenewLogSchedaulTask(ref errormsg);
});
}
}
/// <summary>
/// 定时24点执行
/// </summary>
public class synchronousDataJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
return Task.Run(() => {
string errormsg = null;
MiddleGroundService service = new MiddleGroundService();
service.text(ref errormsg);
//List<cd_tot_bsc_006> wellreal = service.getImportWell(ref errormsg);
//string[] wellNames = wellreal.Select(w => w.WELLNAMES).ToArray();
//service.executeTask(wellNames, ref errormsg);
List<cd_tot_bsc_005> wellbendi = service.getbdImportWell(ref errormsg);
string[] wellbendis = wellbendi.Select(w => w.WELLNAMES).ToArray();
service.postTask(wellbendis,ref errormsg);
});
}
}
}