forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quartz): add clustered jobs support
Fixes quarkusio#3520
- Loading branch information
Showing
21 changed files
with
840 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../runtime/src/main/java/io/quarkus/quartz/runtime/QuarkusQuartzConnectionPoolProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.quartz.runtime; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.quartz.utils.PoolingConnectionProvider; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.InstanceHandle; | ||
|
||
public class QuarkusQuartzConnectionPoolProvider implements PoolingConnectionProvider { | ||
private DataSource dataSource; | ||
private static String dataSourceName; | ||
|
||
public QuarkusQuartzConnectionPoolProvider() { | ||
InstanceHandle<DataSource> instanceHandle; | ||
ArcContainer container = Arc.container(); | ||
boolean useDefaultDataSource = "QUARKUS_QUARTZ_DEFAULT_DATASOURCE".equals(dataSourceName); | ||
if (useDefaultDataSource) { | ||
instanceHandle = container.instance(DataSource.class); | ||
} else { | ||
instanceHandle = container.instance(dataSourceName); | ||
} | ||
if (instanceHandle.isAvailable()) { | ||
this.dataSource = instanceHandle.get(); | ||
} else { | ||
String message = String.format( | ||
"JDBC Store configured but '%s' datasource is missing. You can configure your datasource by following the guide available at: https://quarkus.io/guides/datasource-guide", | ||
useDefaultDataSource ? "default" : dataSourceName); | ||
throw new IllegalStateException(message); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public QuarkusQuartzConnectionPoolProvider(Properties properties) { | ||
this(); | ||
} | ||
|
||
@Override | ||
public DataSource getDataSource() { | ||
return dataSource; | ||
} | ||
|
||
@Override | ||
public Connection getConnection() throws SQLException { | ||
return dataSource.getConnection(); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
// Do nothing as the connection will be closed inside the Agroal extension | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
|
||
} | ||
|
||
static void setDataSourceName(String dataSourceName) { | ||
QuarkusQuartzConnectionPoolProvider.dataSourceName = dataSourceName; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzBuildTimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.quarkus.quartz.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import org.quartz.impl.jdbcjobstore.DriverDelegate; | ||
|
||
import io.quarkus.runtime.annotations.ConfigDocSection; | ||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(name = "quartz", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) | ||
public class QuartzBuildTimeConfig { | ||
/** | ||
* Enable cluster mode or not. | ||
* <p> | ||
* If enabled make sure to set the appropriate cluster properties. | ||
*/ | ||
@ConfigItem | ||
public Optional<Boolean> clustered; | ||
|
||
/** | ||
* The type of store to use. Possible values are: `ram`, `db`. | ||
* <p> | ||
* When using the `db` store type configuration value make sure that you have the agroal datasource configured. See | ||
* <a href="https://quarkus.io/guides/datasource-guide"> Configuring your datasource</a> for more information. | ||
* <p> | ||
* The Quarkus scheduler does not create the necessary scheduling tables in database automatically. | ||
* To create Quartz tables, visit <a href= | ||
* "https://github.com/quartz-scheduler/quartz/blob/master/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore">Quartz | ||
* table creation scripts </a> and pick a script file corresponding to your database in use. | ||
* | ||
*/ | ||
@ConfigItem(defaultValue = "ram") | ||
public StoreType storeType; | ||
|
||
/** | ||
* Quartz JDBC store database configuration | ||
*/ | ||
@ConfigDocSection | ||
@ConfigItem(name = "db") | ||
public QuartzJDBCStoreConfig dbStore; | ||
|
||
@ConfigGroup | ||
public static class QuartzJDBCStoreConfig { | ||
/** | ||
* The Quartz {@link DriverDelegate} driver dialect class to use. | ||
* <p> | ||
* Optionally needed when using the `db` store type {@link QuartzBuildTimeConfig#storeType}. | ||
* <p> | ||
* The delegate class must correspond to the type of driver in use. | ||
* <br> | ||
* <a href= | ||
* "http://www.quartz-scheduler.org/documentation/2.4.0-SNAPSHOT/configuration.html#configuration-of-database-clustering-achieve-fail-over-and-load-balancing-with-jdbc-jobstore">Configuration | ||
* of JDBC-Store</> | ||
*/ | ||
@ConfigItem(defaultValue = "org.quartz.impl.jdbcjobstore.StdJDBCDelegate") | ||
public Optional<String> driverDialect; | ||
|
||
/** | ||
* The name of the datasource to use. | ||
* <p> | ||
* Optionally needed when using the `db` store type {@link QuartzJDBCStoreConfig#storeType}. | ||
* If not specified default to using the default datasource. | ||
*/ | ||
@ConfigItem(name = "name") | ||
public Optional<String> dataSourceName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.