Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of Flyway connectRetriesInterval #33517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test_quarkus;DB_CLOSE_DE

# Flyway config properties
quarkus.flyway.connect-retries=10
quarkus.flyway.connect-retries-interval=100ms
quarkus.flyway.schemas=TEST_SCHEMA
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.locations=db/location1,db/location2
Expand All @@ -15,4 +16,4 @@ quarkus.flyway.migrate-at-start=false
quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.baseline-version=2.0.1
quarkus.flyway.baseline-description=Initial description
quarkus.flyway.callbacks=io.quarkus.flyway.test.FlywayExtensionCallback,io.quarkus.flyway.test.FlywayExtensionCallback2
quarkus.flyway.callbacks=io.quarkus.flyway.test.FlywayExtensionCallback,io.quarkus.flyway.test.FlywayExtensionCallback2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ quarkus.datasource.inventory.jdbc.transactions=xa

# Flyway configuration for missing "users" datasource
quarkus.flyway.users.connect-retries=11
quarkus.flyway.connect-retries-interval=1
quarkus.flyway.users.schemas=USERS_TEST_SCHEMA
quarkus.flyway.users.table=users_flyway_quarkus_history
quarkus.flyway.users.locations=db/users/location1,db/users/location2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ quarkus.datasource.inventory.jdbc.transactions=xa

# Flyway configuration for "users" datasource
quarkus.flyway.users.connect-retries=11
quarkus.flyway.users.connect-retries-interval=2s
quarkus.flyway.users.schemas=USERS_TEST_SCHEMA
quarkus.flyway.users.table=users_flyway_quarkus_history
quarkus.flyway.users.locations=db/users/location1,db/users/location2
Expand All @@ -27,6 +28,7 @@ quarkus.flyway.users.callbacks=io.quarkus.flyway.test.FlywayExtensionCallback

# Flyway configuration for "inventory" datasource
quarkus.flyway.inventory.connect-retries=12
quarkus.flyway.inventory.connect-retries-interval=2s
quarkus.flyway.inventory.schemas=INVENTORY_TEST_SCHEMA
quarkus.flyway.inventory.table=inventory_flyway_quarkus_history
quarkus.flyway.inventory.locations=db/inventory/location1,db/inventory/location2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ quarkus.datasource.inventory.jdbc.max-size=12

# Flyway configuration for default datasource
quarkus.flyway.connect-retries=10
quarkus.flyway.connect-retries-interval=1000ms
quarkus.flyway.schemas=TEST_SCHEMA
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.locations=db/location1,db/location2
Expand All @@ -33,6 +34,7 @@ quarkus.flyway.callbacks=io.quarkus.flyway.test.FlywayExtensionCallback

# Flyway configuration for "users" datasource
quarkus.flyway.users.connect-retries=11
quarkus.flyway.users.connect-retries-interval=10s
quarkus.flyway.users.schemas=USERS_TEST_SCHEMA
quarkus.flyway.users.table=users_flyway_quarkus_history
quarkus.flyway.users.locations=db/users/location1,db/users/location2
Expand All @@ -46,6 +48,7 @@ quarkus.flyway.users.callbacks=io.quarkus.flyway.test.FlywayExtensionCallback

# Flyway configuration for "inventory" datasource
quarkus.flyway.inventory.connect-retries=12
quarkus.flyway.inventory.connect-retries-interval=2s
quarkus.flyway.inventory.schemas=INVENTORY_TEST_SCHEMA
quarkus.flyway.inventory.table=inventory_flyway_quarkus_history
quarkus.flyway.inventory.locations=db/inventory/location1,db/inventory/location2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ quarkus.datasource.users.jdbc.max-size=11

# Flyway configuration for "users" datasource
quarkus.flyway.users.connect-retries=11
quarkus.flyway.users.connect-retries-interval=12
quarkus.flyway.users.schemas=USERS_TEST_SCHEMA
quarkus.flyway.users.table=users_flyway_quarkus_history
quarkus.flyway.users.locations=db/users/location1,db/users/location2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.flyway.runtime;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -19,6 +20,7 @@
class FlywayCreator {

private static final String[] EMPTY_ARRAY = new String[0];
public static final Duration DEFAULT_CONNECT_RETRIES_INTERVAL = Duration.ofSeconds(120L);

private final FlywayDataSourceRuntimeConfig flywayRuntimeConfig;
private final FlywayDataSourceBuildTimeConfig flywayBuildTimeConfig;
Expand Down Expand Up @@ -76,6 +78,8 @@ public Flyway createFlyway(DataSource dataSource) {
if (flywayRuntimeConfig.connectRetries.isPresent()) {
configure.connectRetries(flywayRuntimeConfig.connectRetries.getAsInt());
}
configure.connectRetriesInterval(
(int) flywayRuntimeConfig.connectRetriesInterval.orElse(DEFAULT_CONNECT_RETRIES_INTERVAL).toSeconds());
if (flywayRuntimeConfig.defaultSchema.isPresent()) {
configure.defaultSchema(flywayRuntimeConfig.defaultSchema.get());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.flyway.runtime;

import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -22,12 +23,22 @@ public static FlywayDataSourceRuntimeConfig defaultConfig() {
}

/**
* The maximum number of retries when attempting to connect to the database. After each failed attempt, Flyway will wait 1
* second before attempting to connect again, up to the maximum number of times specified by connectRetries.
* The maximum number of retries when attempting to connect to the database.
* <p>
* After each failed attempt, Flyway will wait up to the configured `connect-retries-interval` duration before
* attempting to connect again, up to the maximum number of times specified by connectRetries.
*/
@ConfigItem
public OptionalInt connectRetries = OptionalInt.empty();

/**
* The maximum time between retries when attempting to connect to the database.
* <p>
* This will cap the interval between connect retries to the value provided.
*/
@ConfigItem(defaultValueDocumentation = "120 seconds")
geoand marked this conversation as resolved.
Show resolved Hide resolved
public Optional<Duration> connectRetriesInterval = Optional.empty();

/**
* Sets the default schema managed by Flyway. This schema name is case-sensitive. If not specified, but <i>schemas</i>
* is, Flyway uses the first schema in that list. If that is also not specified, Flyway uses the default schema for the
Expand Down