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(scheduler): add scheduler configuration and add support for clus…
…tering Fixes quarkusio#3520
- Loading branch information
Showing
15 changed files
with
664 additions
and
20 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
31 changes: 31 additions & 0 deletions
31
...uler/deployment/src/test/java/io/quarkus/scheduler/test/NoDefaultDataSourceErrorTest.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,31 @@ | ||
package io.quarkus.scheduler.test; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NoDefaultDataSourceErrorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest testNoDefaultDatasourceError = new QuarkusUnitTest() | ||
.setExpectedException(IllegalStateException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(SimpleJobs.class) | ||
.addAsResource(new StringAsset("simpleJobs.cron=0/1 * * * * ?\nsimpleJobs.every=1s" + | ||
"\nquarkus.scheduler.state-store=jdbc\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void shouldFailMissingDataSource() throws InterruptedException { | ||
/** | ||
* Should not reach here | ||
*/ | ||
Assertions.fail(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...eduler/deployment/src/test/java/io/quarkus/scheduler/test/NoNamedDataSourceErrorTest.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,33 @@ | ||
package io.quarkus.scheduler.test; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NoNamedDataSourceErrorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest testNoNamedDatasourceError = new QuarkusUnitTest() | ||
.setExpectedException(IllegalStateException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(SimpleJobs.class) | ||
.addAsResource(new StringAsset("simpleJobs.cron=0/1 * * * * ?" + | ||
"\nsimpleJobs.every=1s" + | ||
"\nquarkus.scheduler.state-store=jdbc\n" + | ||
"\nquarkus.scheduler.state-store.datasource.name=ds-name\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void shouldFailMissingDataSource() throws InterruptedException { | ||
/** | ||
* Should not reach here | ||
*/ | ||
Assertions.fail(); | ||
} | ||
|
||
} |
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
62 changes: 62 additions & 0 deletions
62
...ime/src/main/java/io/quarkus/scheduler/runtime/AgroalQuartzConnectionPoolingProvider.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,62 @@ | ||
package io.quarkus.scheduler.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.InstanceHandle; | ||
|
||
public class AgroalQuartzConnectionPoolingProvider implements PoolingConnectionProvider { | ||
final private DataSource dataSource; | ||
|
||
public AgroalQuartzConnectionPoolingProvider() { | ||
SchedulerBuildTimeConfig.SchedulerDatasourceConfig dataSourceConfig = SchedulerConfigHolder | ||
.getSchedulerBuildTimeConfig().stateStore.datasource; | ||
final InstanceHandle<DataSource> dataSourceInstanceHandle; | ||
|
||
if (dataSourceConfig.name.isPresent()) { | ||
dataSourceInstanceHandle = Arc.container().instance(dataSourceConfig.name.get()); | ||
} else { | ||
dataSourceInstanceHandle = Arc.container().instance(DataSource.class); | ||
} | ||
|
||
if (dataSourceInstanceHandle.isAvailable()) { | ||
this.dataSource = dataSourceInstanceHandle.get(); | ||
} else { | ||
final String dataSourceName = dataSourceConfig.name.orElse("_default_"); | ||
throw new IllegalStateException( | ||
"JDBC Store configured but the datasource \"" + dataSourceName + "\" is missing. " | ||
+ "You can configure your " | ||
+ "datasource by following the guide available at: https://quarkus.io/guides/datasource-guide"); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public AgroalQuartzConnectionPoolingProvider(Properties properties) { | ||
this(); | ||
} | ||
|
||
@Override | ||
public DataSource getDataSource() { | ||
return dataSource; | ||
} | ||
|
||
@Override | ||
public Connection getConnection() throws SQLException { | ||
return dataSource.getConnection(); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
|
||
} | ||
} |
Oops, something went wrong.