As I understood from Quartz official documentation, AdoStore have to be used for active data storing like JobDataMap and other data. Correct me if I am wrong.
Beside of this clarification I would like to know is there any way to load job and trigger definition from database. Kind of plugin or something like the Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin
is for reading from xml file.
If there is not, is it the best solution to implement a custom plugin that will read from database or to use some other approach?
[EDIT] Rastko 8/13/2012 11:16:28 AM
From bellow answers I think that I have not describe you the problem good. I would like to load job and trigger configuration from database. Like it is defined in code or in xml like this :
<job>
<name>WriterJob</name>
<group>CommonGroup</group>
<description>Test WriteJob</description>
<job-type>Console.WriteJob, Console</job-type>
</job>
<trigger>
<simple>
<name>WriterJobTrigger</name>
<group>CommonTriggerGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>WriterJob</job-name>
<job-group>CommonGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<repeat-count>-1</repeat-count>
<repeat-interval>10000</repeat-interval>
</simple>
</trigger>
I want to have this on the same way in DataBase. From generated tables for ADOJobStore I see that these tables are more related for tracking of the currently active jobs - tracking of its state, trigger firing, etc.
I hope that I more clear now. Be free to ask me if you need any additional clarification.
I would like to know is there any way to load job and trigger definition from database.
If you are looking to retrieve a list of jobs 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 are building a separate program from the program that is actually executing the jobs, then you just create a scheduler with the same details but don't call scheduler.Start()
If you are looking to add new jobs 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 are looking to add a job to the database without attaching a trigger
Quartz.IJobDetail jobDetail = Quartz.JobBuilder.Create<SimpleJob>()
.WithIdentity(jobName)
.StoreDurably()
.Build();
scheduler.AddJob(jobDetail, false)
If you are looking to schedule execute a one-off existing job, then
Quartz.ITrigger trigger1 = Quartz.TriggerBuilder.Create()
.WithIdentity(triggerName)
.WithSchedule(Quartz.SimpleScheduleBuilder.Create())
.ForJob(jobName)
.Build();
scheduler.ScheduleJob(trigger1);
I am using Quartz for java, but since the basic logic is the same I can say that using XML for task schedulers is not a good idea. At every status change of a job, you will need to change the xml file. Using databases (AdoJobStore in your case) might be more efficient.
have a look at XMLSchedulingDataProcessorPlugin implementation. basically you need to implement ISchedulerPlugin and add you logic to load jobs.
来源:https://stackoverflow.com/questions/11904667/quartz-job-store-is-related-to-active-data