本文整理汇总了C#中IScheduler.CheckExists方法的典型用法代码示例。如果您正苦于以下问题:C# IScheduler.CheckExists方法的具体用法?C# IScheduler.CheckExists怎么用?C# IScheduler.CheckExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScheduler
的用法示例。
在下文中一共展示了IScheduler.CheckExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScheduleTasks
static async void ScheduleTasks(IScheduler scheduler)
{
using (var repo = new Repository())
{
var forms = (await repo.GetForms())
.Where(t => t.TimeRemaining(repo) > TimeSpan.Zero)
.ToList();
foreach (var form in forms)
{
var job = JobBuilder.Create<FormBlockingJob>()
.WithIdentity($"Form{form.form_id}Job")
.UsingJobData("FormId", form.form_id)
.Build();
var schedTime = new DateTimeOffset(form.DateExpired(repo));
var trigger = TriggerBuilder.Create()
.WithIdentity($"Form{form.form_id}JobTrigger")
.StartAt(schedTime)
.ForJob($"Form{form.form_id}Job")
.Build();
if (!scheduler.CheckExists(job.Key))
{
scheduler.ScheduleJob(job, trigger);
_log.Info($"Scheduled block {form.name} at {trigger.StartTimeUtc}");
}
else
{
scheduler.RescheduleJob(trigger.Key, trigger);
_log.Info($"Re-scheduled block {form.name} at {trigger.StartTimeUtc}");
}
}
}
}
示例2: AddJob
private void AddJob(IScheduler scheduler, SystemJob jobItem, Func<Type, IJobActivity> getJob)
{
var jobKey = new JobKey(jobItem.SystemJobId, jobItem.JobClassType);
var type = Type.GetType(jobItem.JobClassType, true);
// Define the Job to be scheduled
var quartzJobDetail = JobBuilder.Create(typeof(QuartzJob))
.WithIdentity(jobKey)
.RequestRecovery()
.Build();
Func<IJobActivity> jobActivityConstructor = () => getJob(type);
Func<DateTime, Action<string>> getAudit = startDateTime =>
message => _schedulerDbTools.CreateSystemJobLogEntry(
jobItem.SystemJobId, startDateTime, DateTime.Now, message,
Thread.CurrentThread.Name, null, jobItem.AllowMultipleInstances);
var section = ConfigurationManager.GetSection("traceContextConfiguration") ?? new TraceContextConfigurationSection();
ITraceContextConfigurator config = (TraceContextConfigurationSection)section;
var contextName = new ContextName(type.FullName, "");
var configuration = config.GetDefault(contextName.Service, contextName.Method);
var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
var traceContext = new TraceContext(configuration, contextName, Guid.NewGuid(), traceSource);
quartzJobDetail.JobDataMap.Add("realization", jobActivityConstructor);
quartzJobDetail.JobDataMap.Add("getAudit", getAudit);
quartzJobDetail.JobDataMap.Add("context", traceContext);
quartzJobDetail.JobDataMap.Add("parameters", jobItem.JobParameters.ToDictionary(pk => pk.Name.ToLowerInvariant(), pv => pv.Value));
// Associate a trigger with the Job
var trigger = TriggerBuilder.Create()
.WithIdentity(jobItem.SystemJobId, jobItem.JobClassType)
.WithSimpleSchedule(x =>
{
x.WithInterval(TimeSpan.FromSeconds(jobItem.Period));
x.RepeatForever();
})
.StartAt(DateTime.UtcNow)
.WithPriority(jobItem.Priority)
.Build();
// Validate that the job doesn't already exists
if (scheduler.CheckExists(jobKey))
{
scheduler.DeleteJob(jobKey);
}
scheduler.ScheduleJob(quartzJobDetail, trigger);
}
示例3: Test
//.........这里部分代码省略.........
scheduler.ScheduleJob(nt2);
var triggerFromDb = (IDailyTimeIntervalTrigger) scheduler.GetTrigger(nt2.Key);
Assert.That(triggerFromDb.StartTimeOfDay.Hour, Is.EqualTo(1));
Assert.That(triggerFromDb.StartTimeOfDay.Minute, Is.EqualTo(2));
Assert.That(triggerFromDb.StartTimeOfDay.Second, Is.EqualTo(3));
Assert.That(triggerFromDb.EndTimeOfDay.Hour, Is.EqualTo(2));
Assert.That(triggerFromDb.EndTimeOfDay.Minute, Is.EqualTo(3));
Assert.That(triggerFromDb.EndTimeOfDay.Second, Is.EqualTo(4));
job.RequestsRecovery = (true);
CalendarIntervalTriggerImpl intervalTrigger = new CalendarIntervalTriggerImpl(
"calint_trig_" + count,
schedId,
DateTime.UtcNow.AddMilliseconds(300),
DateTime.UtcNow.AddMinutes(1),
IntervalUnit.Second,
8);
intervalTrigger.JobKey = job.Key;
scheduler.ScheduleJob(intervalTrigger);
// bulk operations
var info = new Dictionary<IJobDetail, Collection.ISet<ITrigger>>();
IJobDetail detail = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
ITrigger simple = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
var triggers = new Collection.HashSet<ITrigger>();
triggers.Add(simple);
info[detail] = triggers;
scheduler.ScheduleJobs(info, true);
Assert.IsTrue(scheduler.CheckExists(detail.Key));
Assert.IsTrue(scheduler.CheckExists(simple.Key));
// QRTZNET-243
scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("a").DeepClone());
scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("a").DeepClone());
scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("a").DeepClone());
scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("a").DeepClone());
scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("a").DeepClone());
scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("a").DeepClone());
scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("a").DeepClone());
scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("a").DeepClone());
scheduler.Start();
Thread.Sleep(TimeSpan.FromSeconds(3));
scheduler.PauseAll();
scheduler.ResumeAll();
scheduler.PauseJob(new JobKey("job_1", schedId));
scheduler.ResumeJob(new JobKey("job_1", schedId));
scheduler.PauseJobs(GroupMatcher<JobKey>.GroupEquals(schedId));
Thread.Sleep(TimeSpan.FromSeconds(1));
scheduler.ResumeJobs(GroupMatcher<JobKey>.GroupEquals(schedId));
scheduler.PauseTrigger(new TriggerKey("trig_2", schedId));
示例4: ScheduleBehaviorExecution
private static void ScheduleBehaviorExecution(IScheduler scheduler, JToken behaviorModule, string behaviorName)
{
Console.WriteLine(@"Behavior Execution request : {0}", behaviorName);
if (behaviorModule != null)
{
var moduleName = behaviorModule.Value<string>("name");
if (!string.IsNullOrEmpty(moduleName))
{
var jobKey = JobKey.Create(string.Format("Task_{0}", behaviorName), moduleName);
if (scheduler != null && !scheduler.CheckExists(jobKey))
{
var responder = behaviorModule.SelectToken("$.responder");
if (responder != null)
{
string host = responder.Value<string>("Host");
int port = responder.Value<int>("Port");
// Console.WriteLine(@"Host : {0}, Port : {1}", host, port);
IJobDetail detail = JobBuilder.Create<SimpleBehaviorTask>()
.WithIdentity(jobKey)
.Build();
IList<BehaviorInfo> info = new List<BehaviorInfo>();
info.Add(new BehaviorInfo()
{
BehaviorName = behaviorName,
Ip = host,
Port = port,
ModuleName = moduleName
});
detail.JobDataMap.Add("BehaviorInfoList", info);
detail.JobDataMap.Add("BehaviorServerIp", host);
detail.JobDataMap.Add("BehaviorServerPort", port);
detail.JobDataMap.Add("BehaviorName", behaviorName);
ITrigger trigger = TriggerBuilder.Create().ForJob(detail).StartNow().Build();
scheduler.ScheduleJob(detail, trigger);
Console.WriteLine(@"New job about to be scheduled Job : {0}, Module : {1}", jobKey.Name,
jobKey.Group);
}
}
}
}
}
示例5: UnscheduleJob
public bool UnscheduleJob(IScheduler qScheduler, string sJobName, string sJobGroup, string sCronExpression, int iPriority)
{
var jobKey = new JobKey(sJobName, sJobGroup);
if (qScheduler.CheckExists(jobKey))
{
return qScheduler.UnscheduleJob(new TriggerKey(sJobName, sJobGroup));
}
return false;
}
示例6: Initalize
public static void Initalize(DiscoDataContext Database, ISchedulerFactory SchedulerFactory)
{
ReInitalize(Database);
_ReInitializeScheduler = SchedulerFactory.GetScheduler();
var reInitalizeJobDetail = new JobDetailImpl("DiscoLogContextReinialize", typeof(LogReInitalizeJob));
var reInitalizeTrigger = TriggerBuilder.Create()
.WithIdentity("DiscoLogContextReinializeTrigger")
.StartNow()
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 0)) // Midnight
.Build();
if (!_ReInitializeScheduler.CheckExists(reInitalizeTrigger.Key))
_ReInitializeScheduler.ScheduleJob(reInitalizeJobDetail, reInitalizeTrigger);
}