本文整理汇总了C#中IScheduler.AddJob方法的典型用法代码示例。如果您正苦于以下问题:C# IScheduler.AddJob方法的具体用法?C# IScheduler.AddJob怎么用?C# IScheduler.AddJob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScheduler
的用法示例。
在下文中一共展示了IScheduler.AddJob方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NacasujRozesilani
private void NacasujRozesilani()
{
var schedulerFactory = new StdSchedulerFactory();
_casovac = schedulerFactory.GetScheduler();
var job = new JobDetail("rozesilani", null, typeof(Rozesilani));
// Instantiate a trigger using the basic cron syntax.
var trigger = new SimpleTrigger("spust-rozesilani",
null,
TriggerUtils.MakeWeeklyTrigger(DayOfWeek.Monday,7,0).ComputeFirstFireTimeUtc(null).Value,
null,
SimpleTrigger.RepeatIndefinitely,
TimeSpan.FromDays(7)
);
trigger.JobName = job.Name;
job.JobDataMap["sluzba"] = _sluzba;
// Add the job to the scheduler
_casovac.AddJob(job, true);
_casovac.ScheduleJob(trigger);
}
示例2: MonitorService
public MonitorService()
{
this.ServiceName = "Sharp Monitoring Service";
// create the job to be scheduled
Type jobType = typeof(DailyTask);
JobDetail job = new JobDetail(jobType.Name, null, jobType);
ISchedulerFactory schedFact = new StdSchedulerFactory();
sched = schedFact.GetScheduler();
sched.Start();
// schedule daily cron job
Trigger trigger = new CronTrigger("CronTrigger", null, jobType.Name, null, SharpMonitor.Properties.Settings.Default.CornExpression);
sched.AddJob(job, true);
DateTime ft = sched.ScheduleJob(trigger);
// start job immediately if next schedule job is tomorrow
if (ft > DateTime.UtcNow)
{
sched.TriggerJob(jobType.Name, null);
}
}
示例3: ScheduleJob
/// <summary>
/// Schedules a given job and trigger (both wrapped by a <see cref="JobSchedulingBundle" />).
/// </summary>
/// <param name="job">The job.</param>
/// <param name="sched">The sched.</param>
/// <param name="localOverWriteExistingJobs">if set to <c>true</c> [local over write existing jobs].</param>
/// <exception cref="SchedulerException">
/// if the Job or Trigger cannot be added to the Scheduler, or
/// there is an internal Scheduler error.
/// </exception>
public virtual void ScheduleJob(JobSchedulingBundle job, IScheduler sched, bool localOverWriteExistingJobs)
{
if ((job != null) && job.Valid)
{
JobDetail detail = job.JobDetail;
JobDetail dupeJ = sched.GetJobDetail(detail.Name, detail.Group);
if ((dupeJ != null) && !localOverWriteExistingJobs)
{
Log.Info("Not overwriting existing job: " + dupeJ.FullName);
return;
}
if (dupeJ != null)
{
Log.Info(string.Format(CultureInfo.InvariantCulture, "Replacing job: {0}", detail.FullName));
}
else
{
Log.Info(string.Format(CultureInfo.InvariantCulture, "Adding job: {0}", detail.FullName));
}
if (job.Triggers.Count == 0 && !job.JobDetail.Durable)
{
throw new SchedulerException("A Job defined without any triggers must be durable");
}
sched.AddJob(detail, true);
foreach(Trigger trigger in job.Triggers)
{
Trigger dupeT = sched.GetTrigger(trigger.Name, trigger.Group);
trigger.JobName = detail.Name;
trigger.JobGroup = detail.Group;
if (trigger.StartTimeUtc == DateTime.MinValue)
{
trigger.StartTimeUtc = DateTime.UtcNow;
}
if (dupeT != null)
{
Log.Debug(string.Format(CultureInfo.InvariantCulture, "Rescheduling job: {0} with updated trigger: {1}", detail.FullName, trigger.FullName));
if (!dupeT.JobGroup.Equals(trigger.JobGroup) || !dupeT.JobName.Equals(trigger.JobName))
{
Log.Warn("Possibly duplicately named triggers in jobs xml file!");
}
sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
}
else
{
Log.Debug(string.Format(CultureInfo.InvariantCulture, "Scheduling job: {0} with trigger: {1}", detail.FullName, trigger.FullName));
sched.ScheduleJob(trigger);
}
}
AddScheduledJob(job);
}
}
示例4: Test
public void Test(IScheduler scheduler, bool clearJobs, bool scheduleJobs)
{
try
{
if (clearJobs)
{
scheduler.Clear();
}
if (scheduleJobs)
{
ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
ICalendar holidayCalendar = new HolidayCalendar();
// QRTZNET-86
ITrigger t = scheduler.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup"));
Assert.IsNull(t);
AnnualCalendar cal = new AnnualCalendar();
scheduler.AddCalendar("annualCalendar", cal, false, true);
IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
calendarsTrigger.CalendarName = "annualCalendar";
JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
scheduler.ScheduleJob(jd, calendarsTrigger);
// QRTZNET-93
scheduler.AddCalendar("annualCalendar", cal, true, true);
scheduler.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
scheduler.AddCalendar("cronCalendar", cronCalendar, false, true);
scheduler.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
scheduler.AddCalendar("holidayCalendar", holidayCalendar, false, true);
scheduler.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
scheduler.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);
scheduler.AddCalendar("cronCalendar", cronCalendar, true, true);
scheduler.AddCalendar("holidayCalendar", holidayCalendar, true, true);
Assert.IsNotNull(scheduler.GetCalendar("annualCalendar"));
JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
lonelyJob.Durable = true;
lonelyJob.RequestsRecovery = true;
scheduler.AddJob(lonelyJob, false);
scheduler.AddJob(lonelyJob, true);
string schedId = scheduler.SchedulerInstanceId;
int count = 1;
JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
// ask scheduler to re-Execute this job if it was in progress when
// the scheduler went down...
job.RequestsRecovery = true;
IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));
trigger.JobDataMap.Add("key", "value");
trigger.EndTimeUtc = DateTime.UtcNow.AddYears(10);
trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
scheduler.ScheduleJob(job, trigger);
// check that trigger was stored
ITrigger persisted = scheduler.GetTrigger(new TriggerKey("trig_" + count, schedId));
Assert.IsNotNull(persisted);
Assert.IsTrue(persisted is SimpleTriggerImpl);
count++;
job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
// ask scheduler to re-Execute this job if it was in progress when
// the scheduler went down...
job.RequestsRecovery = (true);
trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));
trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
scheduler.ScheduleJob(job, trigger);
count++;
job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob));
// ask scheduler to re-Execute this job if it was in progress when
// the scheduler went down...
job.RequestsRecovery = (true);
trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));
trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
scheduler.ScheduleJob(job, trigger);
count++;
job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
// ask scheduler to re-Execute this job if it was in progress when
// the scheduler went down...
job.RequestsRecovery = (true);
trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));
trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
scheduler.ScheduleJob(job, trigger);
count++;
//.........这里部分代码省略.........
示例5: AddJob6
private void AddJob6(IScheduler scheduler, IJobDetail job, ISimpleTrigger trigger)
{
job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job6", "group1")
.StoreDurably()
.Build();
scheduler.AddJob(job, true);
log.Info("'Manually triggering job6...");
scheduler.TriggerJob(new JobKey("job6", "group1"));
}
示例6: TestMatchers
private void TestMatchers(IScheduler scheduler)
{
scheduler.Clear();
IJobDetail job = JobBuilder.Create<NoOpJob>().WithIdentity("job1", "aaabbbccc").StoreDurably().Build();
scheduler.AddJob(job, true);
SimpleScheduleBuilder schedule = SimpleScheduleBuilder.Create();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("trig1", "aaabbbccc").WithSchedule(schedule).ForJob(job).Build();
scheduler.ScheduleJob(trigger);
job = JobBuilder.Create<NoOpJob>().WithIdentity("job1", "xxxyyyzzz").StoreDurably().Build();
scheduler.AddJob(job, true);
schedule = SimpleScheduleBuilder.Create();
trigger = TriggerBuilder.Create().WithIdentity("trig1", "xxxyyyzzz").WithSchedule(schedule).ForJob(job).Build();
scheduler.ScheduleJob(trigger);
job = JobBuilder.Create<NoOpJob>().WithIdentity("job2", "xxxyyyzzz").StoreDurably().Build();
scheduler.AddJob(job, true);
schedule = SimpleScheduleBuilder.Create();
trigger = TriggerBuilder.Create().WithIdentity("trig2", "xxxyyyzzz").WithSchedule(schedule).ForJob(job).Build();
scheduler.ScheduleJob(trigger);
Collection.ISet<JobKey> jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.AnyGroup());
Assert.That(jkeys.Count, Is.EqualTo(3), "Wrong number of jobs found by anything matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("xxxyyyzzz"));
Assert.That(jkeys.Count, Is.EqualTo(2), "Wrong number of jobs found by equals matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("aaabbbccc"));
Assert.That(jkeys.Count, Is.EqualTo(1), "Wrong number of jobs found by equals matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("aa"));
Assert.That(jkeys.Count, Is.EqualTo(1), "Wrong number of jobs found by starts with matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("xx"));
Assert.That(jkeys.Count, Is.EqualTo(2), "Wrong number of jobs found by starts with matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("cc"));
Assert.That(jkeys.Count, Is.EqualTo(1), "Wrong number of jobs found by ends with matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("zzz"));
Assert.That(jkeys.Count, Is.EqualTo(2), "Wrong number of jobs found by ends with matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("bc"));
Assert.That(jkeys.Count, Is.EqualTo(1), "Wrong number of jobs found by contains with matcher");
jkeys = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("yz"));
Assert.That(jkeys.Count, Is.EqualTo(2), "Wrong number of jobs found by contains with matcher");
Collection.ISet<TriggerKey> tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.AnyGroup());
Assert.That(tkeys.Count, Is.EqualTo(3), "Wrong number of triggers found by anything matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("xxxyyyzzz"));
Assert.That(tkeys.Count, Is.EqualTo(2), "Wrong number of triggers found by equals matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("aaabbbccc"));
Assert.That(tkeys.Count, Is.EqualTo(1), "Wrong number of triggers found by equals matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("aa"));
Assert.That(tkeys.Count, Is.EqualTo(1), "Wrong number of triggers found by starts with matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("xx"));
Assert.That(tkeys.Count, Is.EqualTo(2), "Wrong number of triggers found by starts with matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("cc"));
Assert.That(tkeys.Count, Is.EqualTo(1), "Wrong number of triggers found by ends with matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("zzz"));
Assert.That(tkeys.Count, Is.EqualTo(2), "Wrong number of triggers found by ends with matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("bc"));
Assert.That(tkeys.Count, Is.EqualTo(1), "Wrong number of triggers found by contains with matcher");
tkeys = scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("yz"));
Assert.That(tkeys.Count, Is.EqualTo(2), "Wrong number of triggers found by contains with matcher");
}