From 799d6299a257ea8fe898315ce554c61273cc328a Mon Sep 17 00:00:00 2001 From: Mark Allen <3417310+maallen@users.noreply.github.com> Date: Thu, 17 Aug 2023 09:20:12 +0100 Subject: [PATCH] Added config value to enable/disable Quartz scheduler on a server (#13) * Added config value to enable/disable Quartz scheduler. added docker compose cluster to test API & worker nodes config --- docker/docker-compose-api-worker.yml | 131 ++++++++++++++++++ .../box/l10n/mojito/quartz/QuartzConfig.java | 9 +- 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 docker/docker-compose-api-worker.yml diff --git a/docker/docker-compose-api-worker.yml b/docker/docker-compose-api-worker.yml new file mode 100644 index 0000000000..af4e99f104 --- /dev/null +++ b/docker/docker-compose-api-worker.yml @@ -0,0 +1,131 @@ +version: '2.4' +name: mojito +services: + db: + image: mysql:5.7 + restart: always + healthcheck: + test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ] + interval: 5s + timeout: 30s + retries: 20 + environment: + MYSQL_ROOT_PASSWORD: ChangeMe + MYSQL_DATABASE: mojito + MYSQL_USER: mojito + MYSQL_PASSWORD: ChangeMe + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_bin + - --max-connections=1000 + - --log_error_verbosity=2 + worker: + deploy: + mode: replicated + replicas: 2 + endpoint_mode: vip + resources: + limits: + cpus: '2' + memory: 1G + reservations: + cpus: '1' + memory: 200M + healthcheck: + test: [ "CMD", "curl", "localhost:8080/" ] + interval: 5s + timeout: 10s + retries: 20 + depends_on: + db: + condition: service_healthy + api: + condition: service_healthy + build: + dockerfile: docker/Dockerfile-bk8 + context: ../ + links: + - db + restart: always + environment: + SPRING_APPLICATION_JSON: '{ + "spring.flyway.enabled": "true", + "l10n.flyway.clean" : "false", + "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", + "spring.jpa.hibernate.ddl-auto" : "none", + "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "spring.datasource.username" : "mojito", + "spring.datasource.password" : "ChangeMe", + "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.defer-datasource-initialization" : "false", + "l10n.org.quartz.scheduler.enabled" : "true", + "l10n.org.quartz.jobStore.useProperties" : "true", + "l10n.org.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.quartz.jobStore.isClustered" : "true", + "l10n.org.quartz.threadPool.threadCount" : "10", + "l10n.org.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.quartz.jobStore.dataSource" : "myDS", + "l10n.org.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.quartz.dataSource.myDS.maxConnections" : "12", + "l10n.org.quartz.dataSource.myDS.validationQuery" : "select 1" + }' + api: + deploy: + mode: replicated + replicas: 1 + endpoint_mode: vip + resources: + limits: + cpus: '2' + memory: 1G + reservations: + cpus: '1' + memory: 200M + healthcheck: + test: [ "CMD", "curl", "localhost:8080/" ] + interval: 5s + timeout: 10s + retries: 20 + depends_on: + db: + condition: service_healthy + build: + dockerfile: docker/Dockerfile-bk8 + context: ../ + links: + - db + ports: + - "8080:8080" + restart: always + environment: + SPRING_APPLICATION_JSON: '{ + "spring.flyway.enabled": "true", + "l10n.flyway.clean" : "false", + "spring.jpa.database-platform" : "org.hibernate.dialect.MySQLDialect", + "spring.jpa.hibernate.ddl-auto" : "none", + "spring.datasource.url" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "spring.datasource.username" : "mojito", + "spring.datasource.password" : "ChangeMe", + "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.defer-datasource-initialization" : "false", + "l10n.org.quartz.scheduler.enabled" : "false", + "l10n.org.quartz.jobStore.useProperties" : "true", + "l10n.org.quartz.scheduler.instanceId" : "AUTO", + "l10n.org.quartz.jobStore.isClustered" : "true", + "l10n.org.quartz.threadPool.threadCount" : "10", + "l10n.org.quartz.jobStore.class" : "org.quartz.impl.jdbcjobstore.JobStoreTX", + "l10n.org.quartz.jobStore.driverDelegateClass" : "org.quartz.impl.jdbcjobstore.StdJDBCDelegate", + "l10n.org.quartz.jobStore.dataSource" : "myDS", + "l10n.org.quartz.dataSource.myDS.provider" : "hikaricp", + "l10n.org.quartz.dataSource.myDS.driver" : "com.mysql.jdbc.Driver", + "l10n.org.quartz.dataSource.myDS.URL" : "jdbc:mysql://db:3306/mojito?characterEncoding=UTF-8&useUnicode=true", + "l10n.org.quartz.dataSource.myDS.user" : "mojito", + "l10n.org.quartz.dataSource.myDS.password" : "ChangeMe", + "l10n.org.quartz.dataSource.myDS.maxConnections" : "12", + "l10n.org.quartz.dataSource.myDS.validationQuery" : "select 1" + }' diff --git a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java index 9485b8c51f..f6c33ac8a8 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java +++ b/webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzConfig.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Properties; import java.util.Set; import javax.annotation.PostConstruct; import org.quartz.JobDetail; @@ -32,6 +33,8 @@ public class QuartzConfig { @Autowired(required = false) List jobDetails = new ArrayList<>(); + @Autowired QuartzPropertiesConfig quartzPropertiesConfig; + /** * Starts the scheduler after having removed outdated trigger/jobs * @@ -39,8 +42,12 @@ public class QuartzConfig { */ @PostConstruct void startScheduler() throws SchedulerException { + Properties quartzProps = quartzPropertiesConfig.getQuartzProperties(); removeOutdatedJobs(); - scheduler.startDelayed(2); + if (Boolean.parseBoolean(quartzProps.getProperty("org.quartz.scheduler.enabled", "true"))) { + logger.info("Starting scheduler"); + scheduler.startDelayed(2); + } } void removeOutdatedJobs() throws SchedulerException {