I am planning to write a ASP.NET page to trigger the job on demand. Currently, I am using SimpleTrigger class to trigger the job but none of the __Trigger class supports object type as value in JobParameters and it has come to my knowledge that WCF Tcp binding is used under the hook to pass the parameters to job scheduling engine. I would like to know how to pass custom object (serializable) as job parameters. Thanks for your advice!
Start up the Quartz Scheduler. Schedule two jobs, each job will execute the every ten seconds for a total of times. The scheduler will pass a run-time job parameter of “Green” to the first job instance. The scheduler will pass a run-time job parameter of “Red” to the second job instance.
It has no built-in UI for configuration or monitoring, no useful and reasonably searchable logging or historical review, no support for multiple execution nodes, no administration interface, no alerts or notifications, not to mention buggy recovery mechanisms for failed jobs and missed jobs.
Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.
If you want to schedule multiple jobs in your console application you can simply call Scheduler. ScheduleJob (IScheduler) passing the job and the trigger you've previously created: IJobDetail firstJob = JobBuilder. Create<FirstJob>() .
There are two ways to pass an object that can be retrieved when a Quartz job executes:
Pass the instance in the data map. When you set the job up, add your instance to the map with a key like this:
// Create job etc...
var MyClass _myInstance;
statusJob.JobDataMap.Put("myKey", _myInstance);
// Schedule job...
Retrieve the instance in the job's Execute()
method like this:
public void Execute(IJobExecutionContext context)
{
var dataMap = context.MergedJobDataMap;
var myInstance = (MyClass)dataMap["myKey"];
OR
Add the instance to the scheduler context when you set the job up, like this:
ISchedulerFactory schedFact = new StdSchedulerFactory();
_sched = schedFact.GetScheduler();
_sched.Start();
// Create job etc...
var MyClass _myInstance;
_sched.Context.Put("myKey", myInstance);
// Schedule job...
Retrieve the instance in the job's Execute()
method like this:
public void Execute(IJobExecutionContext context)
{
var schedulerContext = context.Scheduler.Context;
var myInstance = (MyClass)schedulerContext.Get("myKey");
When you schedule a job you can set a JobDataMap
on the JobDetail
object and pass this to your scheduler, there are some limitations described in the quartz.net tutorial. The job can access the data via:
JobDataMap dataMap = context.JobDetail.JobDataMap;
However I prefer to access my job configuration, via an repository injected into the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With