Skip to content

Commit

Permalink
Introduce schedule builder extension methods that attach convenience …
Browse files Browse the repository at this point in the history
…methods to trigger builder, change JobBuilder.NewJob to JobBuilder.Create to follow TriggerBuilder creator method naming convention.
  • Loading branch information
lahma committed Jul 9, 2011
1 parent f2087ff commit 1355bcd
Show file tree
Hide file tree
Showing 28 changed files with 265 additions and 274 deletions.
2 changes: 1 addition & 1 deletion src/Quartz.Examples/example1/SimpleExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public virtual void Run()
log.Info("------- Scheduling Job -------------------");

// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.NewJob<HelloJob>()
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "group1")
.Build();

Expand Down
2 changes: 1 addition & 1 deletion src/Quartz.Examples/example11/LoadExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual void Run()
for (int count = 1; count <= numberOfJobs; count++)
{
IJobDetail job = JobBuilder
.NewJob<SimpleJob>()
.Create<SimpleJob>()
.WithIdentity("job" + count, "group_1")
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();
Expand Down
4 changes: 2 additions & 2 deletions src/Quartz.Examples/example12/RemoteClientExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public virtual void Run()

// define the job and ask it to run

IJobDetail job = JobBuilder.NewJob<SimpleJob>()
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("remotelyAddedJob", "default")
.Build();

Expand All @@ -71,7 +71,7 @@ public virtual void Run()
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("remotelyAddedTrigger", "default")
.ForJob(job.Key)
.WithSchedule(CronScheduleBuilder.CronSchedule("/5 * * ? * *"))
.WithCronSchedule("/5 * * ? * *")
.Build();

// schedule the job
Expand Down
30 changes: 10 additions & 20 deletions src/Quartz.Examples/example13/ClusterExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public virtual void Run(bool inClearJobs, bool inScheduleJobs)
int count = 1;


IJobDetail job = JobBuilder.NewJob<SimpleRecoveryJob>()
IJobDetail job = JobBuilder.Create<SimpleRecoveryJob>()
.WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();
Expand All @@ -125,27 +125,23 @@ public virtual void Run(bool inClearJobs, bool inScheduleJobs)
ISimpleTrigger trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("triger_" + count, schedId)
.StartAt(DateBuilder.FutureDate(1, DateBuilder.IntervalUnit.Second))
.WithSchedule(SimpleScheduleBuilder.Create()
.WithRepeatCount(20)
.WithInterval(TimeSpan.FromSeconds(5)))
.WithSimpleSchedule(x => x.WithRepeatCount(20).WithInterval(TimeSpan.FromSeconds(5)))
.Build();

log.InfoFormat("{0} will run at: {1} and repeat: {2} times, every {3} seconds", job.Key, trigger.GetNextFireTimeUtc(), trigger.RepeatCount, trigger.RepeatInterval.TotalSeconds);

count++;


job = JobBuilder.NewJob<SimpleRecoveryJob>()
job = JobBuilder.Create<SimpleRecoveryJob>()
.WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("triger_" + count, schedId)
.StartAt(DateBuilder.FutureDate(2, DateBuilder.IntervalUnit.Second))
.WithSchedule(SimpleScheduleBuilder.Create()
.WithRepeatCount(20)
.WithInterval(TimeSpan.FromSeconds(5)))
.WithSimpleSchedule(x => x.WithRepeatCount(20).WithInterval(TimeSpan.FromSeconds(5)))
.Build();

log.Info(string.Format("{0} will run at: {1} and repeat: {2} times, every {3} seconds", job.Key, trigger.GetNextFireTimeUtc(), trigger.RepeatCount, trigger.RepeatInterval.TotalSeconds));
Expand All @@ -154,35 +150,31 @@ public virtual void Run(bool inClearJobs, bool inScheduleJobs)
count++;


job = JobBuilder.NewJob<SimpleRecoveryStatefulJob>()
job = JobBuilder.Create<SimpleRecoveryStatefulJob>()
.WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("triger_" + count, schedId)
.StartAt(DateBuilder.FutureDate(1, DateBuilder.IntervalUnit.Second))
.WithSchedule(SimpleScheduleBuilder.Create()
.WithRepeatCount(20)
.WithInterval(TimeSpan.FromSeconds(3)))
.WithSimpleSchedule(x => x.WithRepeatCount(20).WithInterval(TimeSpan.FromSeconds(3)))
.Build();

log.Info(string.Format("{0} will run at: {1} and repeat: {2} times, every {3} seconds", job.Key, trigger.GetNextFireTimeUtc(), trigger.RepeatCount, trigger.RepeatInterval.TotalSeconds));
sched.ScheduleJob(job, trigger);

count++;

job = JobBuilder.NewJob<SimpleRecoveryJob>()
job = JobBuilder.Create<SimpleRecoveryJob>()
.WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("triger_" + count, schedId)
.StartAt(DateBuilder.FutureDate(1, DateBuilder.IntervalUnit.Second))
.WithSchedule(SimpleScheduleBuilder.Create()
.WithRepeatCount(20)
.WithInterval(TimeSpan.FromSeconds(4)))
.WithSimpleSchedule(x => x.WithRepeatCount(20).WithInterval(TimeSpan.FromSeconds(4)))
.Build();

log.Info(string.Format("{0} will run at: {1} & repeat: {2}/{3}", job.Key, trigger.GetNextFireTimeUtc(), trigger.RepeatCount, trigger.RepeatInterval));
Expand All @@ -191,17 +183,15 @@ public virtual void Run(bool inClearJobs, bool inScheduleJobs)
count++;


job = JobBuilder.NewJob<SimpleRecoveryJob>()
job = JobBuilder.Create<SimpleRecoveryJob>()
.WithIdentity("job_" + count, schedId) // put triggers in group named after the cluster node instance just to distinguish (in logging) what was scheduled from where
.RequestRecovery() // ask scheduler to re-execute this job if it was in progress when the scheduler went down...
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("triger_" + count, schedId)
.StartAt(DateBuilder.FutureDate(1, DateBuilder.IntervalUnit.Second))
.WithSchedule(SimpleScheduleBuilder.Create()
.WithRepeatCount(20)
.WithInterval(TimeSpan.FromMilliseconds(4500)))
.WithSimpleSchedule(x => x.WithRepeatCount(20).WithInterval(TimeSpan.FromMilliseconds(4500)))
.Build();

log.Info(string.Format("{0} will run at: {1} & repeat: {2}/{3}", job.Key, trigger.GetNextFireTimeUtc(), trigger.RepeatCount, trigger.RepeatInterval));
Expand Down
8 changes: 4 additions & 4 deletions src/Quartz.Examples/example14/PriorityExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Run()

log.Info("------- Scheduling Jobs -------------------");

IJobDetail job = JobBuilder.NewJob<TriggerEchoJob>()
IJobDetail job = JobBuilder.Create<TriggerEchoJob>()
.WithIdentity("TriggerEchoJob")
.Build();

Expand All @@ -84,7 +84,7 @@ public void Run()
ITrigger trigger1 = TriggerBuilder.Create()
.WithIdentity("PriorityNeg5Trigger5SecondRepeat")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create().WithRepeatCount(1).WithIntervalInSeconds(5))
.WithSimpleSchedule(x => x.WithRepeatCount(1).WithIntervalInSeconds(5))
.WithPriority(1)
.ForJob(job)
.Build();
Expand All @@ -93,15 +93,15 @@ public void Run()
ITrigger trigger2 = TriggerBuilder.Create()
.WithIdentity("Priority5Trigger10SecondRepeat")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create().WithRepeatCount(1).WithIntervalInSeconds(10))
.WithSimpleSchedule(x => x.WithRepeatCount(1).WithIntervalInSeconds(10))
.ForJob(job)
.Build();

// Third trigger has priority 10, and will repeat after 15 seconds
ITrigger trigger3 = TriggerBuilder.Create()
.WithIdentity("Priority10Trigger15SecondRepeat")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create().WithRepeatCount(1).WithIntervalInSeconds(15))
.WithSimpleSchedule(x => x.WithRepeatCount(1).WithIntervalInSeconds(15))
.WithPriority(10)
.ForJob(job)
.Build();
Expand Down
40 changes: 14 additions & 26 deletions src/Quartz.Examples/example2/SimpleTriggerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public virtual void Run()
DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 15);

// job1 will only fire once at date/time "ts"
IJobDetail job = JobBuilder.NewJob<SimpleJob>()
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job1", "group1")
.Build();

Expand All @@ -78,7 +78,7 @@ public virtual void Run()
" times, every " + trigger.RepeatInterval.TotalSeconds + " seconds");

// job2 will only fire once at date/time "ts"
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job2", "group1")
.Build();

Expand All @@ -95,16 +95,14 @@ public virtual void Run()

// job3 will run 11 times (run once and repeat 10 more times)
// job3 will repeat every 10 seconds
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job3", "group1")
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger3", "group1")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInSeconds(10)
.WithRepeatCount(10))
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).WithRepeatCount(10))
.Build();

ft = sched.ScheduleJob(job, trigger);
Expand All @@ -119,9 +117,7 @@ public virtual void Run()
trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger3", "group2")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInSeconds(10)
.WithRepeatCount(2))
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).WithRepeatCount(2))
.ForJob(job)
.Build();

Expand All @@ -133,16 +129,14 @@ public virtual void Run()

// job4 will run 6 times (run once and repeat 5 more times)
// job4 will repeat every 10 seconds
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job4", "group1")
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger4", "group1")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInSeconds(10)
.WithRepeatCount(5))
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).WithRepeatCount(5))
.Build();

ft = sched.ScheduleJob(job, trigger);
Expand All @@ -152,7 +146,7 @@ public virtual void Run()
" times, every " + trigger.RepeatInterval.TotalSeconds + " seconds");

// job5 will run once, five minutes in the future
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job5", "group1")
.Build();

Expand All @@ -168,16 +162,14 @@ public virtual void Run()
" times, every " + trigger.RepeatInterval.TotalSeconds + " seconds");

// job6 will run indefinitely, every 40 seconds
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job6", "group1")
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger6", "group1")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInSeconds(40)
.RepeatForever())
.WithSimpleSchedule(x => x.WithIntervalInSeconds(40).RepeatForever())
.Build();

ft = sched.ScheduleJob(job, trigger);
Expand All @@ -196,16 +188,14 @@ public virtual void Run()

// jobs can also be scheduled after start() has been called...
// job7 will repeat 20 times, repeat every five minutes
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job7", "group1")
.Build();

trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger7", "group1")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInMinutes(5)
.WithRepeatCount(20))
.WithSimpleSchedule(x => x.WithIntervalInMinutes(5).WithRepeatCount(20))
.Build();

ft = sched.ScheduleJob(job, trigger);
Expand All @@ -215,7 +205,7 @@ public virtual void Run()
" times, every " + trigger.RepeatInterval.TotalSeconds + " seconds");

// jobs can be fired directly... (rather than waiting for a trigger)
job = JobBuilder.NewJob<SimpleJob>()
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job8", "group1")
.StoreDurably()
.Build();
Expand Down Expand Up @@ -243,9 +233,7 @@ public virtual void Run()
trigger = (ISimpleTrigger) TriggerBuilder.Create()
.WithIdentity("trigger7", "group1")
.StartAt(startTime)
.WithSchedule(SimpleScheduleBuilder.Create()
.WithIntervalInMinutes(5)
.WithRepeatCount(20))
.WithSimpleSchedule(x => x.WithIntervalInMinutes(5).WithRepeatCount(20))
.Build();

ft = sched.RescheduleJob(trigger.Key, trigger);
Expand Down
Loading

0 comments on commit 1355bcd

Please sign in to comment.