Beispiel #1
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="request"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static async Task AddTask(Request request, Action <Request, Action <Request> > action)
        {
            On();
            IJobDetail job = JobBuilder.Create <RunJob>()
                             .WithIdentity(request.Id + constJob, ID)
                             .Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity(request.Id + constTrigger, ID)
                               .StartNow()
                               .WithCronSchedule(request.CronExpress)
                               .Build();

            SchedTask schedTask = new SchedTask(ID, job, trigger, request, sched, action);

            // 传值过去
            job.JobDataMap["schedTask"] = schedTask;

            schedTasks.Add(schedTask);
            await sched?.ScheduleJob(job, trigger);
        }
Beispiel #2
0
 /// <summary>
 /// 删除任务
 /// </summary>
 /// <param name="schedTask"></param>
 /// <returns></returns>
 public static Task <bool> DeleteSchedTask(SchedTask schedTask)
 {
     return(sched.DeleteJob(schedTask.Jobkey));
 }
Beispiel #3
0
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public static Task <bool> DeleteSchedTask(string requestId)
        {
            SchedTask schedTask = schedTasks.Where(t => t.JobDetail.Key.Name == requestId + constJob).FirstOrDefault();

            return(DeleteSchedTask(schedTask));
        }