I would like to know if there is a way to load the task and initiate the definition from the database.
If you want to get a list of tasks from the database, you can do something like:
Quartz.IScheduler scheduler ; .... var details = (from groupName in scheduler.GetJobGroupNames() from jobKey in scheduler.GetJobKeys( Quartz.Impl.Matchers.GroupMatcher<Quartz.JobKey> .GroupEquals(groupName)) select new { GroupName = groupName, JobName = jobKey.Name , triggers = scheduler.GetTriggersOfJob(jobKey) } );
This syntax is for Quartz 2.0.
If you create a separate program from a program that actually performs tasks, then you simply create a scheduler with the same details, but do not call scheduler.Start ()
If you want to add new tasks to your database, you can do something like:
(where SimpleJob is the C # class name of your job)
string jobName = ... string triggerName = ... string cronExpression = ... Quartz.IScheduler scheduler = ... Quartz.IJobDetail jobDetail = Quartz.JobBuilder.Create<SimpleJob>() .WithIdentity(jobName) .StoreDurably() .Build(); Quartz.ITrigger trigger = Quartz.TriggerBuilder.Create() .WithIdentity(triggerName) .WithSchedule(Quartz.CronScheduleBuilder.CronSchedule(cronExpression) .ForJob(jobName) .Build(); scheduler.ScheduleJob(jobDetail, trigger);
If you want to add a task to the database without connecting a trigger
Quartz.IJobDetail jobDetail = Quartz.JobBuilder.Create<SimpleJob>() .WithIdentity(jobName) .StoreDurably() .Build(); scheduler.AddJob(jobDetail, false)
If you plan to complete a one-time existing task, then
Quartz.ITrigger trigger1 = Quartz.TriggerBuilder.Create() .WithIdentity(triggerName) .WithSchedule(Quartz.SimpleScheduleBuilder.Create()) .ForJob(jobName) .Build(); scheduler.ScheduleJob(trigger1);
source share