private static async Task RunProgramRunExample() { try { NameValueCollection props = new NameValueCollection { { "quartz.serializer.type", "binary" } }; StdSchedulerFactory factory = new StdSchedulerFactory(); IScheduler scheduler = await factory.GetScheduler(); await scheduler.Start(); IJobDetail job = JobBuilder.Create <HelloJob>() .WithIdentity("job1", "group1") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartNow() .WithSimpleSchedule(x => x.WithIntervalInSeconds(10) .RepeatForever()) .Build(); await scheduler.ScheduleJob(job, trigger); await Task.Delay(TimeSpan.FromSeconds(60)); await scheduler.Shutdown(); } catch (SchedulerException se) { Console.WriteLine(se); } }
private IScheduler _scheduler; // after Start, and until shutdown completes, references the scheduler object // starts the scheduler, defines the jobs and the triggers public void Start() { if (_scheduler != null) { throw new InvalidOperationException("Already started."); } NameValueCollection properties = new NameValueCollection { { "quartz.serializer.type", "binary" } }; // Grab the Scheduler instance from the Factory var schedulerFactory = new StdSchedulerFactory(properties); _scheduler = schedulerFactory.GetScheduler().Result; _scheduler.Start().Wait(); // define the job and tie it to our HelloJob class IJobDetail userEmailsJob = JobBuilder.Create <SendUserEmailsJob>() .WithIdentity("SendUserEmails", "group1") .Build(); // Trigger the job to run now, and then repeat at midnight 12am everyday ITrigger userEmailsTrigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithSchedule(CronScheduleBuilder.CronSchedule("0 0 0 * * ?")) .Build(); //.WithDailyTimeIntervalSchedule( // x => x.WithIntervalInSeconds(30)) // Tell quartz to schedule the job using our trigger _scheduler.ScheduleJob(userEmailsJob, userEmailsTrigger).Wait(); }
[Category("fragile")] // TODO seems that we have some trouble on Linux with this public async Task ReschedulingTriggerShouldKeepOriginalNextFireTime() { NameValueCollection properties = new NameValueCollection(); properties["quartz.serializer.type"] = TestConstants.DefaultSerializerType; ISchedulerFactory factory = new StdSchedulerFactory(properties); IScheduler scheduler = await factory.GetScheduler(); await scheduler.Start(); var job = JobBuilder.Create <NoOpJob>().Build(); IOperableTrigger trigger = (IOperableTrigger)TriggerBuilder.Create() .WithSimpleSchedule(x => x.WithIntervalInHours(1).RepeatForever()) .ForJob(job) .StartNow() .Build(); await scheduler.ScheduleJob(job, trigger); trigger = (IOperableTrigger)await scheduler.GetTrigger(trigger.Key); Assert.That(trigger.GetPreviousFireTimeUtc(), Is.EqualTo(null)); var previousFireTimeUtc = DateTimeOffset.UtcNow.AddDays(1); trigger.SetPreviousFireTimeUtc(previousFireTimeUtc); trigger.SetNextFireTimeUtc(trigger.GetFireTimeAfter(previousFireTimeUtc)); await scheduler.RescheduleJob(trigger.Key, trigger); trigger = (IOperableTrigger)await scheduler.GetTrigger(trigger.Key); Assert.That(trigger.GetNextFireTimeUtc().Value.UtcDateTime, Is.EqualTo(previousFireTimeUtc.AddHours(1).UtcDateTime).Within(TimeSpan.FromSeconds(5))); await scheduler.Shutdown(true); }
public async static void Start() { ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); IScheduler scheduler = await schedulerFactory.GetScheduler(); await scheduler.Start(); IJobDetail job = JobBuilder.Create <SensorFetchJob>() .WithIdentity("purpleair-sensor-fetch") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInMinutes(5) .OnEveryDay() .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0)) ) .Build(); await scheduler.ScheduleJob(job, trigger); await scheduler.TriggerJob(new JobKey("purpleair-sensor-fetch")); }
public static void Start() { IJobDetail job = JobBuilder.Create <CreateSearchIndexJob>() .WithIdentity("CreateSearchIndexJob") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInSeconds(30) .OnEveryDay() ) .ForJob(job) .WithIdentity("CreateSearchIndexJobTrigger") .StartNow() .WithCronSchedule("0 0/30 * * * ?") //每30分钟创建索引 .Build(); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sc = sf.GetScheduler(); sc.ScheduleJob(job, trigger); sc.Start(); }
/// <summary> /// CronSchedule 根据字符串来替代之前的简单计划表,日历计划表,每天计划表 /// </summary> public static void Fun10() { var sche = StdSchedulerFactory.GetDefaultScheduler(); sche.Start(); var job = JobBuilder.Create <MyJob>() .Build(); //秒 分 时 天 月 年 周 //1. 天或者周必须有一个是?(?表示模糊) //2. * 表示所有值即,秒位为*表示每秒执行一次 //3. - 表示范围,分钟位为10-12表示每个小时的10,11,12分执行一次 //4. , 表示每个值即,分钟位为10,20,30表示每个小时的10,20,30分执行一次 //5. / 表示递增,秒位为0/5表示0,5,10,15,20,25,30,35,40,45,50,55秒执行一次 //例子: // * * * * * ? => 每秒执行一次 // 0/5 * * * * ? => 5s执行一次 // 0 * * * * ? => 1min执行一次 // 0 0 1 * * ? => 每个月1号执行一次 // 地址:https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontrigger.html var trigger = TriggerBuilder.Create().StartNow().WithCronSchedule("0/1 * * * * ?").Build(); sche.ScheduleJob(job, trigger); }
/// <summary> /// 指定时间执行任务 /// </summary> /// <typeparam name="T">任务类,必须实现IJob接口</typeparam> /// <param name="jobName">工作名称<param> /// <param name="group">组名称</param> /// <param name="parameter">参数 可为空</param> /// <param name="cronExpression">cron表达式,即指定时间点的表达式</param> /// <summary> public void ExecuteByCron <T>(string jobName, string group, JobDataMapParameter parameter, string cronExpression) where T : IJob { IScheduler scheduler = factory.GetScheduler(); IJobDetail job = JobBuilder.Create <T>() .WithIdentity(jobName, group) .Build(); //DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddSeconds(1), 2); //DateTimeOffset endTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddYears(2), 3); if (parameter != null) { job.JobDataMap.Put(parameter.Key, parameter.Value); } ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create() //.StartAt(startTime).EndAt(endTime) .WithCronSchedule(cronExpression) .Build(); scheduler.ScheduleJob(job, trigger); scheduler.Start(); }
public async Task Start() { if (_scheduler != null) { throw new InvalidOperationException("Already started."); } var schedulerFactory = new StdSchedulerFactory(); _scheduler = await schedulerFactory.GetScheduler(); _scheduler.JobFactory = new JobFactory(_container); await _scheduler.Start(); foreach (var weatherSetting in _weatherSettings.ZipCodeIntervals) { var voteJob = JobBuilder.Create <WeatherDataLoadJob>().UsingJobData("ZipCode", weatherSetting.ZipCode).Build(); var voteJobTrigger = TriggerBuilder.Create().StartNow().WithSimpleSchedule(s => s.WithIntervalInSeconds(weatherSetting.Interval).RepeatForever()).Build(); await _scheduler.ScheduleJob(voteJob, voteJobTrigger); } }
public bool Start(HostControl hostControl) { if (JobConfig.factory == null) { JobConfig.factory = new StdSchedulerFactory(); JobConfig.scheduler = JobConfig.factory.GetScheduler(); JobConfig.scheduler.Start(); //创建循环Job IJobDetail job = JobBuilder.Create <LoopJob>().WithIdentity("LoopJob", "group1").Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("LoopJobtrigger", "group1") .WithCronSchedule("0 0/5 * * * ?") //30分种执行一次 .StartAt(new DateTimeOffset(DateTime.Now.AddSeconds(5))) .Build(); JobConfig.scheduler.ScheduleJob(job, trigger); } else { JobConfig.scheduler.Start(); } return(true); }
public static void Register() { var factory = new StdSchedulerFactory(); var scheduler = factory.GetScheduler(); scheduler.Start(); var job = JobBuilder.Create <BackupJob>().WithIdentity("Backup", "PerformBackup").Build(); string backupScheduleUtc = ConfigurationManager.GetConfigurationValue("ParameterConfigFileLocation", "BackupScheduleUTC"); var scheduleData = backupScheduleUtc.Split(','); int hour = 0; int minute = 0; if (scheduleData.Length.Equals(2)) { hour = scheduleData[0].To <int>(); minute = scheduleData[1].To <int>(); } var trigger = TriggerBuilder.Create().WithIdentity("Backup", "PerformBackup").WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(hour, minute).InTimeZone(TimeZoneInfo.Utc)).Build(); scheduler.ScheduleJob(job, trigger); }
public static void Start() { IJobDetail emailJob = JobBuilder.Create <QuartzTriggerForEmail>() .WithIdentity("job2") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInSeconds(30) .OnEveryDay() ) .ForJob(emailJob) .WithIdentity("trigger2") .StartNow() .WithCronSchedule("0 0 12 * * ?") .Build(); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sc = sf.GetScheduler(); sc.ScheduleJob(emailJob, trigger); sc.Start(); }
public static void Start() { IJobDetail job = JobBuilder.Create <BalanceJob>() .WithIdentity("BalanceJob") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInSeconds(30) .OnEveryDay() ) .ForJob(job) .WithIdentity("BalanceJobTrigger") .StartNow() .WithCronSchedule("0 30 23 * * ?") //每日的23:30 执行分红程序 .Build(); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sc = sf.GetScheduler(); sc.ScheduleJob(job, trigger); sc.Start(); }
public static void Start(ZD_SyncTaskConfig plan) { try { IScheduler scheduler = _scheduler; if (scheduler.IsStarted) { } else { } scheduler.Start(); IDictionary <string, Object> jobData = new Dictionary <string, Object>(); jobData.Add("Plan", plan); //Type objType = typeof(T); Type objType = Type.GetType("OThinker.H3.Portal." + plan.JobClassName.Trim()); IJobDetail job = JobBuilder.Create(objType) .WithIdentity(plan.JobClassName.Trim(), plan.JobClassName.Trim() + "GroupName") .SetJobData(new JobDataMap(jobData)) .Build(); ITrigger trigger; trigger = TriggerBuilder.Create() .WithIdentity(plan.JobClassName.Trim() + "TriggerName", plan.JobClassName.Trim() + "GroupName") .WithCronSchedule(plan.CronExplain.Trim()) .ForJob(job) .Build(); scheduler.ScheduleJob(job, trigger); _logger.InfoFormat(plan.MissionName + "=============启动时间时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } catch (Exception e) { _logger.InfoFormat("============="); _logger.InfoFormat(e.Message.ToString()); throw; } }
public async Task TestResumeTriggersBeforeAddJob() { await scheduler.PauseTriggers(GroupMatcher <TriggerKey> .GroupEquals("abc")); await scheduler.ResumeTriggers(GroupMatcher <TriggerKey> .GroupEquals("abc")); IJobDetail jobDetail = JobBuilder.Create <NoOpJob>() .WithIdentity("test") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("test", "abc") .WithCronSchedule("* * * * * ?") .Build(); await scheduler.ScheduleJob(jobDetail, trigger); TriggerState state = await scheduler.GetTriggerState(new TriggerKey("test", "abc")); Assert.That(state, Is.EqualTo(TriggerState.Normal)); Assert.That(state, Is.Not.EqualTo(TriggerState.Paused)); await scheduler.PauseTriggers(GroupMatcher <TriggerKey> .GroupEquals("abc")); state = await scheduler.GetTriggerState(new TriggerKey("test", "abc")); Assert.That(state, Is.EqualTo(TriggerState.Paused)); Assert.That(state, Is.Not.EqualTo(TriggerState.Normal)); await scheduler.ResumeTriggers(GroupMatcher <TriggerKey> .GroupEquals("abc")); state = await scheduler.GetTriggerState(new TriggerKey("test", "abc")); Assert.That(state, Is.EqualTo(TriggerState.Normal)); Assert.That(state, Is.Not.EqualTo(TriggerState.Paused)); }
private static void RefreshJobList(IScheduler sched) { Console.WriteLine("重新加载Job..."); lock (syncRoot) { sched.Clear(); JobList.Clear(); JobList.Add(new JobInfo { Name = "PolicySyncPage", RequestType = RequestType.Get, CronExpression = "5/10 * * * * ?", RequestURL = "http://127.0.0.1:5080/PolicySyncPage.aspx" }); JobList.Add(new JobInfo { Name = "WebForm1", RequestType = RequestType.Get, CronExpression = "0/10 * * * * ?", RequestURL = "http://127.0.0.1:5080/WebForm1.aspx" }); foreach (JobInfo jobInfo in JobList) { JobDataMap dataMap = new JobDataMap(); dataMap.Add("JobInfo", jobInfo); IJobDetail job = JobBuilder.Create <JinRi.PolicyJob.ConsoleApplication1.SchedulerJob>().SetJobData(dataMap).WithIdentity(jobInfo.Name, "Job_" + jobInfo.GroupName).WithDescription(jobInfo.Description).Build(); ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create().WithIdentity("Trigger_" + jobInfo.Name, "Trigger_" + jobInfo.GroupName).WithCronSchedule(jobInfo.CronExpression).Build(); sched.ScheduleJob(job, trigger); } } }
/// <summary> /// Starts a job that checks for orphans and removes them from the scheduler. /// </summary> public static async void StartOrphanCheckerJob() { //Debug.WriteLine(string.Format("Orphan checker started at: ", DateTime.Now)); // Grab the Scheduler instance from the Factory IScheduler scheduler = await _SchedulerFactory.GetScheduler(); // Check if the job exists. JobKey jobID = new JobKey("OrphanCheckerJob", "OrphanChecker"); // Define the job and tie it to our OrphanCheckerJob class IJobDetail job = JobBuilder.Create <OrphanCheckerJob>() .WithIdentity(jobID) .Build(); // Trigger the job to run now, and then repeat every 10 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity("OrphanCheckerJob", "OrphanChecker") .StartAt(DateTime.Now) .WithSimpleSchedule(x => x .WithIntervalInMinutes(1) .RepeatForever()) .Build(); }
public Job(string jobName, string jobDesc, string workTime) { if (string.IsNullOrEmpty(jobName)) { throw new ArgumentNullException("jobName is null"); } if (string.IsNullOrEmpty(workTime)) { throw new ArgumentNullException("workTime is null"); } //创建一个作业 Detail = JobBuilder.Create <T>() .WithIdentity(jobName) .WithDescription(jobDesc) .Build(); //创建一个触发器 Trigger = TriggerBuilder.Create() .WithIdentity(string.Format("{0}_Trigger", jobName)) .WithCronSchedule(workTime) .Build(); }
static void Main(string[] args) { // construct a scheduler factory ISchedulerFactory schedFact = new StdSchedulerFactory(); // get a scheduler, start the schedular before triggers or anything else IScheduler sched = schedFact.GetScheduler(); sched.Start(); // create job IJobDetail job = JobBuilder.Create <SimpleJob>() .WithIdentity("job1", "group1") .Build(); // create trigger ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever()) .Build(); // Schedule the job using the job and trigger sched.ScheduleJob(job, trigger); }
public void TestCanScheduleJobAlongsideService() { const string calendarName = "calendar"; HostFactory.Run(configurator => { configurator.UseTestHost(); configurator.Service <SampleService>(s => { s.ConfigureQuartzScheduler(() => new SchedulerConfigurator() .WithCalendar(() => new QuartzCalendarConfig(calendarName, GetCalendar())) ); s.ConstructUsing(settings => new SampleService()); s.WhenStarted((service, control) => service.Start()); s.WhenStopped((service, control) => service.Stop()); s.ScheduleQuartzJob(q => q.WithJob(() => JobBuilder.Create <SampleJob>().Build()).AddTrigger(() => TriggerBuilder.Create().WithSimpleSchedule(builder => builder.WithRepeatCount(0)).ModifiedByCalendar(calendarName).Build())); }).StartAutomatically(); }); Assert.IsTrue(HasJobRun.HasRun); }
public void ShouldRespectDisallowConcurrentExecutionAttribute() { var key = new JobKey("job2", "grp2"); var job1 = JobBuilder.Create <LongRunningJob>().WithIdentity(key).StoreDurably(true) .Build(); var trigger = TriggerBuilder.Create().WithSimpleSchedule(s => s.WithIntervalInSeconds(3).WithRepeatCount(10)).Build(); job1.ConcurrentExecutionDisallowed.Should().BeTrue("Concurrent execution should be disabled in JobDetail"); job1.JobDataMap["counter"] = 0; job1.JobDataMap[DisallowConcurrentExecution] = false; _scheduler.ScheduleJob(job1, trigger); _scheduler.Start(); Thread.Sleep(7.Seconds()); var jobMap = _scheduler.GetJobDetail(key).JobDataMap; jobMap.GetBooleanValue(DisallowConcurrentExecution) .Should() .BeTrue("Concurrent execution was indicated as enabled inside job execution"); }
public void ScheduleJob( string jobName, string jobGroup, Type jobType, string triggerName, TriggerType triggerType, IDictionary <string, object> jobData) { var jobBuilder = JobBuilder.Create(jobType); if (!string.IsNullOrEmpty(jobName) || !string.IsNullOrEmpty(jobGroup)) { jobBuilder = jobBuilder.WithIdentity(jobName ?? Guid.NewGuid().ToString(), jobGroup); } if (jobData != null) { jobBuilder = jobBuilder.UsingJobData(new JobDataMap(jobData)); } TriggerBuilder triggerBuilder = ApplyTriggerData(triggerName, triggerType, TriggerBuilder.Create()); _scheduler.ScheduleJob(jobBuilder.Build(), triggerBuilder.Build()); }
public Agendamento(TimeSpan interval, int prioridade = 10) { var name = typeof(TJob).Name; var groupName = name + "Group"; Log.Application.DebugFormat( "Configurando agendamento para {0} a cada {1}s", name, interval.TotalSeconds); this.job = JobBuilder.Create <TJob>() .WithIdentity(name, groupName) .Build(); this.trigger = TriggerBuilder.Create() .WithIdentity(name + "Trigger", groupName) .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(interval.TotalSeconds.ToInt()) .RepeatForever() .WithMisfireHandlingInstructionIgnoreMisfires()) .WithPriority(prioridade) .Build(); }
public static void StartJobSchedule <T>(string cronExpression, string jobName, string groupName) where T : IJob { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); if (scheduler.CheckExists(new JobKey(jobName, groupName))) { throw new Exception("Já existe job agendado."); } IJobDetail job = JobBuilder.Create <T>() .WithIdentity(jobName, groupName) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trg_" + jobName, groupName) .WithPriority(1) .WithCronSchedule(cronExpression) .Build(); scheduler.ScheduleJob(job, trigger); }
private void InitializedData(PortalDbContext context, IScheduler sched) { if (!context.DockerRepositories.Any()) { var repo = new DockerRepository { Name = "DockerHub", Schema = null, Registry = null, Repository = "dotnetspider/spiders.startup", CreationTime = DateTime.Now, UserName = "", Password = "" }; context.DockerRepositories.Add(repo); var spider = new Entity.Spider { Name = "cnblogs", Cron = "0 1 */1 * * ?", Repository = "dotnetspider/spiders.startup", Type = "DotnetSpider.Spiders.CnblogsSpider", Tag = "latest", CreationTime = DateTime.Now }; context.Spiders.Add(spider); context.SaveChanges(); var trigger = TriggerBuilder.Create().WithCronSchedule(spider.Cron).WithIdentity(spider.Id.ToString()) .Build(); var qzJob = JobBuilder.Create <TriggerJob>().WithIdentity(spider.Id.ToString()) .WithDescription(spider.Name) .RequestRecovery(true).Build(); sched.ScheduleJob(qzJob, trigger).GetAwaiter().GetResult(); } }
public static void Start() { // Grab the Scheduler instance from the Factory var props = new NameValueCollection { { "quartz.serializer.type", "binary" } }; var factory = new StdSchedulerFactory(props); IScheduler scheduler = factory.GetScheduler().GetAwaiter().GetResult(); IJobDetail job = JobBuilder.Create <RetriveIPAJob>().Build(); // Trigger the job to run now, and then repeat every 10 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInMinutes(Utils.SchedulerIntervalMinutes) .RepeatForever()) .Build(); scheduler.ScheduleJob(job, trigger); }
public static void Start() { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job = JobBuilder.Create <Foo>().Build(); //default ITrigger trigger = TriggerBuilder.Create() .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(30) .RepeatForever()) .Build(); //ITrigger trigger = TriggerBuilder.Create() //.StartNow() //.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(11, 11)) // execute job daily at 9:30 //.Build(); scheduler.ScheduleJob(job, trigger); //scheduler.Shutdown(); }
public static void Start() { IJobDetail job = JobBuilder.Create <ResetTodayStatisticJob>() .WithIdentity("ResetTodayStatisticJob") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithDailyTimeIntervalSchedule (s => s.WithIntervalInSeconds(30) .OnEveryDay() ) .ForJob(job) .WithIdentity("ResetTodayStatisticJobTrigger") .StartNow() .WithCronSchedule("0 50 22 * * ?") //每日晚上22:50点执行 .Build(); ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sc = sf.GetScheduler(); sc.ScheduleJob(job, trigger); sc.Start(); }
public async Task <ActionResult> Start() { ViewBag.Message = "Job scheduler started."; // get a scheduler, start the schedular before triggers or anything else var sched = await Scheduler.Instance.Current; await sched.Start(); // create job var job = JobBuilder.Create <SimpleJob>() .WithIdentity("job1", "group1") .Build(); // create trigger var trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()) .Build(); // Schedule the job using the job and trigger await sched.ScheduleJob(job, trigger); return(View()); }
public void SimpleReschedulingTest() { var job = JobBuilder.Create <SimpleJob>().WithIdentity("job1", "group1").Build(); var trigger1 = TriggerBuilder.Create() .ForJob(job) .WithIdentity("trigger1", "group1") .StartAt(DateTimeOffset.Now.AddSeconds(30)) .Build(); _scheduler.ScheduleJob(job, trigger1); job = _scheduler.GetJobDetail(job.Key); Assert.That(job, Is.Not.Null); var trigger2 = TriggerBuilder.Create() .ForJob(job) .WithIdentity("trigger1", "group1") .StartAt(DateTimeOffset.Now.AddSeconds(60)) .Build(); _scheduler.RescheduleJob(trigger1.Key, trigger2); job = _scheduler.GetJobDetail(job.Key); Assert.That(job, Is.Not.Null); }
private async void btnStartJob_Click(object sender, RoutedEventArgs e) { try { // Grab the Scheduler instance from the Factory IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); // and start it off await scheduler.Start(); IJobDetail job = JobBuilder.Create <HelloJob>() .WithIdentity("job1", "group1") .Build(); // Trigger the job to run now, and then repeat every 10 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(10) .RepeatForever()) .Build(); await scheduler.ScheduleJob(job, trigger); // some sleep to show what's happening Thread.Sleep(TimeSpan.FromSeconds(3)); // and last shut down the scheduler when you are ready to close your program await scheduler.Shutdown(); } catch (SchedulerException se) { Console.WriteLine(se); } }