Quartz Job Scheduler Setup
Since Jmix v.1.2, the recommended way to integrate Quartz Job Scheduler is to use the Quartz add-on. This section is helpful only if you don’t use the Quartz add-on. |
Quartz Job Scheduler is used in various parts of the framework for running scheduled tasks. This section describes how to include Quartz in your project and set up its job store for different databases.
-
Add the following dependency to the
build.gradle
file:implementation 'org.springframework.boot:spring-boot-starter-quartz'
-
Add the following properties to the
application.properties
file:main.datasource.studio.liquibase.excludePrefixes = qrtz_ spring.quartz.job-store-type = jdbc
-
If you are using PostgreSQL, add the following property:
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
-
If you are using Microsoft SQL Server, add the following property:
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.MSSQLDelegate
-
If you are using HSQL, PostgreSQL, MySQL or Oracle database, you can rely on automatic creation of the Quartz tables at the application start. Just add the following property:
spring.quartz.jdbc.initialize-schema = always
-
If you are using Microsoft SQL Server, you have to create the database schema manually, because the script provided by Quartz cannot be executed automatically by the Spring Boot mechanism. Follow these steps:
-
After adding the Quartz dependency (see above) and reloading Gradle project, find the
tables_sqlServer.sql
file inside the Quartz JAR. You can do it by pressing Shift twice (Navigate → Search Everything) in your IDE and entering the file name. -
Execute the content of the
tables_sqlServer.sql
file against your database using a SQL client of your choice. Notice that you have to replace theenter_db_name_here
placeholder in the firstUSE
command with the name of your database. -
Add the following property to the application:
spring.quartz.jdbc.initialize-schema = never
-