Search code examples
javaspringquartz-schedulerrestorequartz

Quartz load jobs from db filtering by group criteria


In my spring boot application is used quartz starter. All jobs that produced are adding in runtime into DB. The DB is used different services, but jobs can be handled only services which was populating DB with jobs.

Starting any service I need guarantee that only jobs produced by this one will be added into quartz job context. We can detect these jobs by specified groups.

Questions are:

1

How to manage job loader with minimum changes (using out the box solution) filtering jobs only by specified group (different groups should not be handled in this job context)?

2

How to register in quartz scheduler only JobClasses valid for the current service? (as example service could support googleRetry only jobs, but DB contains fbRetry and linkedInRetry. The instance should load googleRetry jobs only.) I hope it could manage job loading from different side.

3

I've detected in quartz DriverDelegate next method

/**
 * <p>
 * Get the names of all of the triggers in the given group and state that
 * have misfired - according to the given timestamp.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @return an array of <code>{@link
 * org.quartz.utils.Key}</code> objects
 */
List<TriggerKey> selectMisfiredTriggersInGroupInState(Connection conn,
    String groupName, String state, long ts) throws SQLException;

but no usages of it. I expect it should be used in special recovery mode (in case of recovering filtering by group as example) but no usages. I tried to manage CustomDelegate upgrading selectTriggersForRecoveringJobs with functionality i need, but getting a CURSOR issue in this case.

Is it possible to configure quartz recovery mode with using selectMisfiredTriggersInGroupInState, how?


Solution

  • It seems attention was concentrated on different things. Quartz scheduler definitely should know its own jobs. Additional idea manage quartz schedulers for different services like different ones (similar for same cluster only). Solution is to specify scheduler name:

    spring:
      quartz:
        job-store-type: jdbc
        properties:
          org:
            quartz:
              thread-pool:
                thread-count: 5
              scheduler:
                instanceName: mailCluster
    

    Scheduler instance name is used in different tables in SCHED_NAME column. And this is important condition for filtering jobs\triggers at load time from db for the instance.