Commit 66cb4ce3 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Allow to configure Quartz's "overwriteExistingJobs" property"

Closes gh-13582
parent 910e6dc4
...@@ -90,6 +90,8 @@ public class QuartzAutoConfiguration { ...@@ -90,6 +90,8 @@ public class QuartzAutoConfiguration {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setJobFactory(new AutowireCapableBeanJobFactory( schedulerFactoryBean.setJobFactory(new AutowireCapableBeanJobFactory(
this.applicationContext.getAutowireCapableBeanFactory())); this.applicationContext.getAutowireCapableBeanFactory()));
schedulerFactoryBean
.setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs());
if (!this.properties.getProperties().isEmpty()) { if (!this.properties.getProperties().isEmpty()) {
schedulerFactoryBean schedulerFactoryBean
.setQuartzProperties(asProperties(this.properties.getProperties())); .setQuartzProperties(asProperties(this.properties.getProperties()));
...@@ -103,8 +105,6 @@ public class QuartzAutoConfiguration { ...@@ -103,8 +105,6 @@ public class QuartzAutoConfiguration {
if (this.triggers != null && this.triggers.length > 0) { if (this.triggers != null && this.triggers.length > 0) {
schedulerFactoryBean.setTriggers(this.triggers); schedulerFactoryBean.setTriggers(this.triggers);
} }
schedulerFactoryBean
.setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs());
customize(schedulerFactoryBean); customize(schedulerFactoryBean);
return schedulerFactoryBean; return schedulerFactoryBean;
} }
......
...@@ -38,14 +38,14 @@ public class QuartzProperties { ...@@ -38,14 +38,14 @@ public class QuartzProperties {
private JobStoreType jobStoreType = JobStoreType.MEMORY; private JobStoreType jobStoreType = JobStoreType.MEMORY;
/** /**
* Additional Quartz Scheduler properties. * Whether configured jobs should overwrite existing job definitions.
*/ */
private final Map<String, String> properties = new HashMap<>(); private boolean overwriteExistingJobs = false;
/** /**
* Allows to reschedule existing jobs. * Additional Quartz Scheduler properties.
*/ */
private boolean overwriteExistingJobs = false; private final Map<String, String> properties = new HashMap<>();
private final Jdbc jdbc = new Jdbc(); private final Jdbc jdbc = new Jdbc();
...@@ -57,14 +57,6 @@ public class QuartzProperties { ...@@ -57,14 +57,6 @@ public class QuartzProperties {
this.jobStoreType = jobStoreType; this.jobStoreType = jobStoreType;
} }
public Map<String, String> getProperties() {
return this.properties;
}
public Jdbc getJdbc() {
return this.jdbc;
}
public boolean isOverwriteExistingJobs() { public boolean isOverwriteExistingJobs() {
return this.overwriteExistingJobs; return this.overwriteExistingJobs;
} }
...@@ -73,6 +65,14 @@ public class QuartzProperties { ...@@ -73,6 +65,14 @@ public class QuartzProperties {
this.overwriteExistingJobs = overwriteExistingJobs; this.overwriteExistingJobs = overwriteExistingJobs;
} }
public Map<String, String> getProperties() {
return this.properties;
}
public Jdbc getJdbc() {
return this.jdbc;
}
public static class Jdbc { public static class Jdbc {
private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/quartz/impl/" private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/quartz/impl/"
......
...@@ -160,24 +160,17 @@ public class QuartzAutoConfigurationTests { ...@@ -160,24 +160,17 @@ public class QuartzAutoConfigurationTests {
} }
@Test @Test
public void withOverwriteExistingJobsParameter() { public void withOverwriteExistingJobs() {
this.contextRunner.withUserConfiguration(OverwriteTriggerConfiguration.class) this.contextRunner.withUserConfiguration(OverwriteTriggerConfiguration.class)
.withPropertyValues("spring.quartz.overwriteExistingJobs=true", .withPropertyValues("spring.quartz.overwrite-existing-jobs=true")
"test-name=withConfiguredJobAndOverwrittenTrigger")
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(Scheduler.class); assertThat(context).hasSingleBean(Scheduler.class);
Scheduler scheduler = context.getBean(Scheduler.class); Scheduler scheduler = context.getBean(Scheduler.class);
assertThat(scheduler.getJobDetail(JobKey.jobKey("fooJob")))
.isNotNull();
Trigger fooTrigger = scheduler Trigger fooTrigger = scheduler
.getTrigger(TriggerKey.triggerKey("fooTrigger")); .getTrigger(TriggerKey.triggerKey("fooTrigger"));
assertThat(fooTrigger).isNotNull(); assertThat(fooTrigger).isNotNull();
assertThat(((SimpleTrigger) fooTrigger).getRepeatInterval()) assertThat(((SimpleTrigger) fooTrigger).getRepeatInterval())
.isEqualTo(30000); .isEqualTo(30000);
Thread.sleep(1000L);
this.output.expect(
containsString("withConfiguredJobAndOverwrittenTrigger"));
this.output.expect(containsString("jobDataValue"));
}); });
} }
......
...@@ -146,7 +146,7 @@ content into your application. Rather, pick only the properties that you need. ...@@ -146,7 +146,7 @@ content into your application. Rather, pick only the properties that you need.
spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema.
spring.quartz.job-store-type=memory # Quartz job store type. spring.quartz.job-store-type=memory # Quartz job store type.
spring.quartz.properties.*= # Additional Quartz Scheduler properties. spring.quartz.properties.*= # Additional Quartz Scheduler properties.
spring.quartz.overwriteExistingJobs=false # Whether overwriting existing job definitions is enabled. spring.quartz.overwrite-existing-jobs=false # Whether configured jobs should overwrite existing job definitions.
# REACTOR ({sc-spring-boot-autoconfigure}/reactor/core/ReactorCoreProperties.{sc-ext}[ReactorCoreProperties]) # REACTOR ({sc-spring-boot-autoconfigure}/reactor/core/ReactorCoreProperties.{sc-ext}[ReactorCoreProperties])
spring.reactor.stacktrace-mode.enabled=false # Whether Reactor should collect stacktrace information at runtime. spring.reactor.stacktrace-mode.enabled=false # Whether Reactor should collect stacktrace information at runtime.
......
...@@ -5996,6 +5996,10 @@ NOTE: By default, the database is detected and initialized by using the standard ...@@ -5996,6 +5996,10 @@ NOTE: By default, the database is detected and initialized by using the standard
provided with the Quartz library. It is also possible to provide a custom script by provided with the Quartz library. It is also possible to provide a custom script by
setting the `spring.quartz.jdbc.schema` property. setting the `spring.quartz.jdbc.schema` property.
By default, jobs created by configuration will not overwrite already registered jobs that
have been read from a persistent job store. To enable overwriting existing job definitions
set the `spring.quartz.overwrite-existing-jobs` property.
Quartz Scheduler configuration can be customized by using Quartz configuration properties Quartz Scheduler configuration can be customized by using Quartz configuration properties
(`spring.quartz.properties.*`) and `SchedulerFactoryBeanCustomizer` beans, which allow (`spring.quartz.properties.*`) and `SchedulerFactoryBeanCustomizer` beans, which allow
programmatic `SchedulerFactoryBean` customization. programmatic `SchedulerFactoryBean` customization.
...@@ -6030,15 +6034,6 @@ in a similar manner, as shown in the following example: ...@@ -6030,15 +6034,6 @@ in a similar manner, as shown in the following example:
} }
---- ----
Jobs created by configuration will not overwrite already registered jobs that have been
read in from a persistent job store. To enable overwriting existing job definitions set
`spring.quartz.overwriteExistingJobs` property:
[source,properties,indent=0]
----
spring.quartz.overwriteExistingJobs=true
----
[[boot-features-integration]] [[boot-features-integration]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment