Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

With the help of the Scheduler Quartz Component generic Blueriq jobs can be scheduled, unscheduled or rescheduled. Generic jobs do not need to have knowledge about the specific scheduler used (in our case, about Quartz), they only need to implement the scheduling interfaces defined in Blueriq.

Details about the needed interfaces and how to implement and schedule a custom job are detailed in this article.

Table of Contents

Creating custom jobs

A custom jobs should implement both in Java and .Net the IJob Blueriq interface. The execute(IExecutionContext context) method defined in the IJob interface is going to be executed when the job is executed. The job's scheduler and the job's parameters can be accessed from the execution context: context.getParameters() and context.getScheduler().

Example

 

UI Expand
titleJava

The Blueriq scheduler when executes the job looks for an object with the scheduled job's type in the application context. As a consequence at execution a bean of the scheduled job type should be available in the application context.

 

Code Block
@Component
public class MyJob implements IJob {

 @Override
 public void execute(IExecutionContext context) {
	IJobParamters paramters = context.getParameters();
	IScheduler scheduler = context.getScheduler();     
 }
}
UI Expand
title.NET
Code Block
public class TestJob : BQ.IJob
{
    public void execute(BQ.IExecutionContext context)
    {
        BQ.IJobParamters parameters = context.getParameters();
        BQ.IScheduler scheduler = context.getScheduler();     
    }
}

Scheduling, unscheduling and rescheduling custom jobs

Scheduling custom jobs

For scheduling custom jobs the IScheduler.schedule method can be used. It has the following four parameters four parameters:

  • the class of the job
  • the paramteres of the job
    • can be created by calling the IScheduler.createJobParameters().
  • the schedule of the job
    • can be created by calling IScheduler.getScheduleBuilder().onDate(Date date) or IScheduler.getScheduleBuilder().now() methods
  • the ID of the job
    • can be created by calling the IScheduler.createJobId(String jobId)
UI Expand
titleJava

Custom jobs can be scheduled using the SpringQuartzScheduler class in the Quartz Scheduler Component.

Code Block
IJobParameters parameters = scheduler.createJobParameters();
ISchedule schedule = scheduler.getScheduleBuilder().now();
IJobId jobId = scheduler.createJobId();
scheduler.schedule(MyJob.class, parameters, schedule, jobId);
UI Expand
title.NET

Custom jobs can be scheduled using the QuartzScheduler class in the Quartz Scheduler Component.

Code Block
BQ.IJobParameters parameters = scheduler.createJobParameters();
BQ.ISchedule schedule = scheduler.getScheduleBuilder().now();
BQ.IJobId jobId = scheduler.createJobId();
scheduler.schedule(typeof(MyJob), parameters, schedule, jobId);

Unscheduling custom jobs

For unschdeuling custom jobs the IScheduler.unschedule method can be used which has only one paramters, the id of the job.

 

UI Expand
titleJava

Custom jobs can be unscheduled using the SpringQuartzScheduler class in the Quartz Scheduler Component.

Code Block
scheduler.unschedule(jobId);
UI Expand
title.NET

Custom jobs can be unscheduled using the QuartzScheduler class in the Quartz Scheduler Component.

Code Block
scheduler.unschedule(jobId);

Rescheduling custom jobs

For reschdeuling custom jobs the IScheduler.reschedule method can be used. This method has two parameters: de id of the job and the it's new schedule.

 

UI Expand
titleJava

Custom jobs can be rescheduled using the SpringQuartzScheduler class in the Quartz Scheduler Component.

Code Block
BQ.ISchedule schedule = scheduler.getScheduleBuilder().now();
scheduler.reschedule(jobId, schedule);
UI Expand
title.NET

Custom jobs can be rescheduled using the QuartzScheduler class in the Quartz Scheduler Component.

Code Block
BQ.ISchedule schedule = scheduler.getScheduleBuilder().now();
scheduler.reschedule(jobId, schedule);