I have a Quartz job which reads and writes to IJobExecutionContext.JobDetail.JobDataMap, and the data is (appears to be) persisted in the JOB_DATA column of dbo.QRTZ_JOB_DETAILS.
While this works fine (each run of the job reads/writes the persisted data), I would like to query (from outside the context of the Quartz job itself) the value(s) in the JobDataMap. Ideally, I would like to be able to write the values for the job as well.
I could (presumably) read the column from the SQL datatable, and deserialise it back into a JobDetail object (?), but that seems a bit "back door" - and I'm not sure about how to deserialise it.
Or, maybe I could instantiate some Quartz object which will do the heavy lifting for me. For example (pseudocode):
var jobDetail = Quartz.JobDetail.Deserialize("MyJob")
var jobDataMap = jobDetail.JobDataMap;
var key = "MyKey";
var oldValue = jobDataMap.Contains(key) ? jobDataMap.GetIntValue(key) : 0;
var newValue = fnCrazyCalculation(oldValue);
jobDataMap.PutAsString(key, newValue);
Any suggestions ?
*** Edit ***
I tried creating an instance of this:
var schedulerFactory = new StdSchedulerFactory();
var scheduler = schedulerFactory.GetScheduler();
var jobKey = new Quartz.JobKey("MyJob","Work");
var jobDetail = scheduler.GetJobDetail(jobKey);
...but this seemed to need the Quartz properties set in app.config, but I'm not sure if I can just set just enough to get the job details from the database.
ie. I copied this from the actual Job project:
<quartz>
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />
<add key="quartz.plugin.xml.fileNames" value="~/QuartzJobs.xml" />
<add key="quartz.dataSource.quartzDataSource.connectionStringName" value="ConsoleApp3.Properties.Settings.Quartz" />
<add key="quartz.dataSource.quartzDataSource.provider" value="SqlServer-20" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.jobStore.dataSource" value="quartzDataSource" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.clustered" value="true" />
<add key="quartz.scheduler.instanceId" value="AUTO" />
</quartz>
...but this seemed to then need the QuartzJobs.xml definitions and the class which actually implements the job.
question from:
https://stackoverflow.com/questions/65924003/how-to-read-job-data-for-quartz-net-job 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…