|
@@ -21,10 +21,10 @@ namespace wispro.sp.api.Job
|
|
|
/// <param name="trigger">触发器</param>
|
|
|
public static async Task Add(Type type, JobKey jobKey, ITrigger trigger = null)
|
|
|
{
|
|
|
- Init();
|
|
|
- _scheduler = await _schedulerFactory.GetScheduler();
|
|
|
+ await Init();
|
|
|
+ //_scheduler = await _schedulerFactory.GetScheduler();
|
|
|
|
|
|
- await _scheduler.Start();
|
|
|
+ //await _scheduler.Start();
|
|
|
|
|
|
if (trigger == null)
|
|
|
{
|
|
@@ -38,6 +38,28 @@ namespace wispro.sp.api.Job
|
|
|
.WithIdentity(jobKey)
|
|
|
.Build();
|
|
|
|
|
|
+
|
|
|
+ await _scheduler.ScheduleJob(job, trigger);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async Task AddMailJob(string Subject,string Body,string To)
|
|
|
+ {
|
|
|
+ await Init();
|
|
|
+
|
|
|
+
|
|
|
+ var trigger = TriggerBuilder.Create()
|
|
|
+ .WithDescription("发送邮件通知")
|
|
|
+ .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).WithRepeatCount(0))
|
|
|
+ .Build();
|
|
|
+
|
|
|
+ var job = JobBuilder.Create(typeof(MailJob))
|
|
|
+ .WithIdentity("邮件任务")
|
|
|
+ .Build();
|
|
|
+
|
|
|
+ job.JobDataMap.Put("Subject",Subject);
|
|
|
+ job.JobDataMap.Put("Body", Body);
|
|
|
+ job.JobDataMap.Put("To", To);
|
|
|
+
|
|
|
await _scheduler.ScheduleJob(job, trigger);
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -65,11 +87,14 @@ namespace wispro.sp.api.Job
|
|
|
/// <summary>
|
|
|
/// 初始化
|
|
|
/// </summary>
|
|
|
- private static void Init()
|
|
|
+ private static async Task Init()
|
|
|
{
|
|
|
- if (_schedulerFactory == null)
|
|
|
+ if (_scheduler == null)
|
|
|
{
|
|
|
_schedulerFactory = new StdSchedulerFactory();// ServiceLocator.Services.GetService<ISchedulerFactory>();
|
|
|
+ _scheduler = await _schedulerFactory.GetScheduler();
|
|
|
+
|
|
|
+ await _scheduler.Start();
|
|
|
}
|
|
|
}
|
|
|
}
|