public bool StartJob(string jobName, IJobExecutor handler, string cron)
 {
     lock (joblocker)
     {
         var existjob = Jobs.Exists(x => x.JobName == jobName);
         if (existjob)
         {
             return(false);
         }
         //string InnerJobId = Guid.NewGuid().ToString();
         JobDetailImpl jobdetail = new JobDetailImpl(jobName, typeof(RuanalInnerJob));
         jobdetail.Description = "内部调度任务";
         Quartz.ITrigger triger    = null;
         var             isrunonce = cron.ToLower() == "runonce";
         if (isrunonce)
         {
             var ttriger = new Quartz.Impl.Triggers.SimpleTriggerImpl("trigger_" + jobName);
             ttriger.RepeatCount    = 0;
             ttriger.RepeatInterval = TimeSpan.FromSeconds(1);
             triger = ttriger;
         }
         else
         {
             var ttriger = new Quartz.Impl.Triggers.CronTriggerImpl("trigger_" + jobName);
             ttriger.CronExpressionString = cron;
             triger = ttriger;
         }
         JobContext jobitem = new JobContext()
         {
             //  InnerJobId = InnerJobId,
             IsRunOnce   = isrunonce,
             JobName     = jobName,
             JobDetail   = jobdetail,
             LastRunTime = null,
             OnInvoke    = handler
         };
         jobitem.Triggers.Add(triger);
         Jobs.Add(jobitem);
         Scheduler.ScheduleJob(jobdetail, triger);
         return(true);
     }
 }
        private async Task ExecuteMissions()
        {
            _scheduler = await _schedulerFactory.GetScheduler();

            Quartz.ITrigger trigger = null;


            if (RunParam.WorkType == ToolWorkType.AllDay)
            {
                //每分钟执行一次
                trigger = TriggerBuilder.Create().WithSimpleSchedule(p => p.WithIntervalInMinutes(1)).Build();
            }
            else if (RunParam.WorkType == ToolWorkType.TimeToTime)
            {
                string[] start = RunParam.TimeToStart.Split(':');
                string[] stop  = RunParam.TimeToStop.Split(':');
                trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(p => p.OnEveryDay()
                                                                                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(int.Parse(start[0]), int.Parse(start[1])))
                                                                                .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(int.Parse(stop[0]), int.Parse(stop[1])))
                                                                                .WithIntervalInSeconds(10))
                          .Build();
            }
            else
            {
                //未支持,立马返回
                return;
            }

            IJobDetail jobDetail = JobBuilder.Create <PingJob>().WithIdentity("ping", "healthCheck").UsingJobData(new JobDataMap(new Dictionary <string, PingHostedService> {
                { "runData", this }
            })).Build();

            await _scheduler.Start();

            NLogMgr.DebugLog(_programLog, "定时任务开始");
            await _scheduler.ScheduleJob(jobDetail, trigger);

            return;
        }
Beispiel #3
0
        }   // End Constructor

        public async System.Threading.Tasks.Task StartJobs(System.Threading.CancellationToken stoppingToken)
        {
            this._stopppingToken   = stoppingToken;
            this._schedulerFactory = new Quartz.Impl.StdSchedulerFactory();
            this._scheduler        = await this._schedulerFactory.GetScheduler();

            await this._scheduler.Start();

            Quartz.IJobDetail job1 = Quartz.JobBuilder.Create <Job1>()
                                     .WithIdentity("job1", "gtoup")
                                     .Build();

            Quartz.ITrigger trigger1 = Quartz.TriggerBuilder.Create()
                                       .WithIdentity("trigger_10_sec", "group")
                                       .StartNow()
                                       .WithSimpleSchedule(x => x
                                                           .WithIntervalInSeconds(10)
                                                           .RepeatForever())
                                       .Build();

            Quartz.IJobDetail job2 = Quartz.JobBuilder.Create <Job2>()
                                     .WithIdentity("job2", "group")
                                     .Build();

            Quartz.ITrigger trigger2 = Quartz.TriggerBuilder.Create()
                                       .WithIdentity("trigger_20_sec", "group")
                                       .StartNow()
                                       .WithSimpleSchedule(x => x
                                                           .WithIntervalInSeconds(20)
                                                           .RepeatForever())
                                       .Build();

            await this._scheduler.ScheduleJob(job1, trigger1, this._stopppingToken);

            await this._scheduler.ScheduleJob(job2, trigger2, this._stopppingToken);
        } // End Task StartJobs
 public bool VetoJobExecution(Trigger trigger, JobExecutionContext context)
 {
     return false;
 }
 public void TriggerMisfired(Trigger trigger)
 {
 }
 public void TriggerFired(Trigger trigger, JobExecutionContext context)
 {
 }
 public void TriggerComplete(Trigger trigger, JobExecutionContext context,
     SchedulerInstruction triggerInstructionCode)
 {
 }