QuartzService execution with additional datsource

Hi,

When i try to execute quartzService.executeNow which i am manully executing. I am getting getting Caused by: org.quartz.JobPersistenceException: The job (DEFAULT.Predue SMS-NPDC D15 D3 with Link) referenced by the trigger does not exist. error.
When debug i found that this quartzService is using Main datasource to fetch database details.

I had created additional database properties and i am trying to set configuration to Quartz service but still i am getting Main datasource as configuration instead additional datasource


@Autowired
    private QuartzService quartzService;


 **quartzService.executeNow**(schedulerApprovalLog.getName(), schedulerApprovalLog.getChannel());

Is there any way to execute quartz service with additional datasource instead main data source.

Below code i tried but not worked.


spring.quartz.properties.org.quartz.jobStore.dataSource=digitalDataSource
spring.quartz.properties.org.quartz.jobStore.tablePrefix=QRTZ_
spring.quartz.properties.org.quartz.dataSource.digitalDataSource.driver=org.postgresql.Driver
spring.quartz.properties.org.quartz.dataSource.digitalDataSource.URL=jdbc:postgresql://localhost:5432/yourdb
spring.quartz.properties.org.quartz.dataSource.digitalDataSource.user=postgres
spring.quartz.properties.org.quartz.dataSource.digitalDataSource.password=postgres

Hi,

With the following properties I managed to use another database to store Quartz data:

Notes:

  1. remoteQuartzDatasource is not the name of additional data store in terms of Jmix. It’s just some name for datasource created specifically for Quartz (it’s configured with properties in the same list)
  2. Additional database (quartzexternaldb) is exists and contains all tables required for Quartz.

Properties

spring.quartz.properties.org.quartz.scheduler.instanceName=MyScheduler
spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
spring.quartz.properties.org.quartz.jobStore.useProperties=true
spring.quartz.properties.org.quartz.jobStore.dataSource=remoteQuartzDatasource
spring.quartz.properties.org.quartz.jobStore.isClustered=false
spring.quartz.properties.org.quartz.jobStore.tablePrefix=QRTZ_
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.driver=org.postgresql.Driver
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.URL=jdbc:postgresql://localhost:5432/quartzexternaldb
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.user=dbuser
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.password=password
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.maxConnections=5
spring.quartz.properties.org.quartz.dataSource.remoteQuartzDatasource.provider=hikaricp
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

Please try.

Regards,
Ivan

How to debug which datastore it is referring as i checked in logs getting error it was referring to primary database only.

Caused by: org.quartz.JobPersistenceException: The job (DEFAULT.TEST) referenced by the trigger does not exist.

Hi,

The following can be useful to debug:

  • JobStoreSupport#getConnection and JobStoreSupport#getDataSource
  • Within you job: inspect Scheduler - there you should find JobStore with info about datasource. Scheduler can be acquired via JobExecutionContext.
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    try {
        Scheduler scheduler = jobExecutionContext.getScheduler();
        
		// your business logic
    } catch (SchedulerException e) {
        throw new RuntimeException("Unable to get scheduler", e);
    }
}

Regards,
Ivan