feat(新增): 设置每日时间表
This commit is contained in:
parent
d66882cb0e
commit
7783b97141
|
@ -11,4 +11,9 @@ public interface IJobService
|
||||||
/// 将jobDetail放在触发器中
|
/// 将jobDetail放在触发器中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void PutJobDetail4Trigger();
|
void PutJobDetail4Trigger();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置每日时间表
|
||||||
|
/// </summary>
|
||||||
|
void SetJobWithDaily();
|
||||||
}
|
}
|
|
@ -72,4 +72,40 @@ public class JobService : IJobService
|
||||||
scheduler.ScheduleJob(trigger).GetAwaiter().GetResult();
|
scheduler.ScheduleJob(trigger).GetAwaiter().GetResult();
|
||||||
scheduler.Start().GetAwaiter().GetResult();
|
scheduler.Start().GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置每日时间表
|
||||||
|
/// </summary>
|
||||||
|
public void SetJobWithDaily()
|
||||||
|
{
|
||||||
|
var stdSchedulerFactory = new StdSchedulerFactory();
|
||||||
|
var scheduler = stdSchedulerFactory.GetScheduler().GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
var jobDetail = JobBuilder.Create<SimJob>()
|
||||||
|
.UsingJobData("username", "用户名")
|
||||||
|
.UsingJobData("password", "密码")
|
||||||
|
.StoreDurably() // 设置作业为持久的
|
||||||
|
.WithIdentity("simpleJob", "简单的JOB")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
scheduler.AddJob(jobDetail,true).GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
var trigger = TriggerBuilder.Create()
|
||||||
|
.ForJob(jobDetail)
|
||||||
|
.UsingJobData("trigger", "trigger值")
|
||||||
|
.WithIdentity("testTrigger", "测试发出器")
|
||||||
|
.StartNow()
|
||||||
|
// TODO StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(20, 0)):触发器从每天的20:00(晚上8点)开始。
|
||||||
|
// TODO EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(22, 0)):触发器在每天的22:00(晚上10点)结束。
|
||||||
|
// TODO WithIntervalInSeconds(5):在开始和结束时间之间,触发器将每5秒触发一次作业。
|
||||||
|
.WithDailyTimeIntervalSchedule(x => x.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(16, 0))
|
||||||
|
.EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(22, 0))
|
||||||
|
.OnDaysOfTheWeek(DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Thursday)
|
||||||
|
.WithIntervalInSeconds(2)
|
||||||
|
)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
scheduler.ScheduleJob(trigger).GetAwaiter().GetResult();
|
||||||
|
scheduler.Start().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,4 +31,15 @@ public class JobInitController(IJobService jobService) : ControllerBase
|
||||||
jobService.PutJobDetail4Trigger();
|
jobService.PutJobDetail4Trigger();
|
||||||
return Result<string>.Success("将jobDetail中的一些信息放在触发器中,简化写法");
|
return Result<string>.Success("将jobDetail中的一些信息放在触发器中,简化写法");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 3. 设置每日时间表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpHead]
|
||||||
|
public Result<string> SetJobWithDaily()
|
||||||
|
{
|
||||||
|
jobService.SetJobWithDaily();
|
||||||
|
return Result<string>.Success();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue