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

Add db-scheduler implementation of the Event Scheduler and Deadline Manager #2727

Merged
merged 28 commits into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
67191e1
Add DbScheduler event scheduler.
gklijs May 23, 2023
2780550
Add DbScheduler deadline manager.
gklijs May 24, 2023
91d01bc
Suppress duplications related to Db scheduler, since it resembles Job…
gklijs May 24, 2023
88f85a2
Clarify javadoc
gklijs May 24, 2023
35bef9c
Cleaned up the code.
gklijs May 24, 2023
cfaa99a
Add auto configuration.
gklijs May 24, 2023
8b4d479
Create the task-instance without a reference to the actual task.
gklijs May 25, 2023
102e7c8
Add a more compact pojo's for db-scheduler integration, which are use…
gklijs May 26, 2023
ed669f6
End span in a finally block, improve javadoc.
gklijs May 30, 2023
5c0f834
Update messaging/src/test/java/org/axonframework/utils/DbSchedulerTes…
gklijs May 30, 2023
e15495d
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
dca44dd
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
37ceedb
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
c84f634
Update messaging/src/test/java/org/axonframework/eventhandling/schedu…
gklijs May 30, 2023
cf81157
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
35eb206
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
c0b57bb
Update messaging/src/test/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
9572487
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
bb7a6e5
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
b6d085b
Update messaging/src/main/java/org/axonframework/eventhandling/schedu…
gklijs May 30, 2023
160fc38
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
1f96d15
Update messaging/src/main/java/org/axonframework/deadline/dbscheduler…
gklijs May 30, 2023
c418f28
Fixed most of the review comments.
gklijs May 30, 2023
6e1c3f1
Optionally start the scheduler using the `Lifecycle`. With Spring Boo…
gklijs May 30, 2023
42890b8
Change the parent of the exception to a generic `AxonException` as th…
gklijs May 31, 2023
a5d71a1
Update messaging/src/main/java/org/axonframework/eventhandling/schedu…
gklijs Jun 1, 2023
e23ecc2
Some cleanup in tests, making pojo constructors public, and a few oth…
gklijs Jun 1, 2023
b0dd235
Make it easier to enable the human-readable pojo's when using Spring …
gklijs Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions integrationtests/pom.xml
Expand Up @@ -101,6 +101,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.kagkarlsson</groupId>
<artifactId>db-scheduler</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
Expand Down
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2010-2023. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.integrationtests.deadline.dbscheduler;

import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.SchedulerBuilder;
import com.github.kagkarlsson.scheduler.task.Task;
import org.axonframework.common.transaction.NoTransactionManager;
import org.axonframework.config.Configuration;
import org.axonframework.config.ConfigurationScopeAwareProvider;
import org.axonframework.deadline.DeadlineManager;
import org.axonframework.deadline.dbscheduler.DbSchedulerDeadlineManager;
import org.axonframework.integrationtests.deadline.AbstractDeadlineManagerTestSuite;
import org.axonframework.serialization.TestSerializer;
import org.hsqldb.jdbc.JDBCDataSource;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.*;
import org.mockito.junit.jupiter.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.sql.DataSource;

@ContextConfiguration
@ExtendWith(MockitoExtension.class)
@ExtendWith(SpringExtension.class)
class DbSchedulerDeadlineManagerTest extends AbstractDeadlineManagerTestSuite {

@Autowired
private DataSource dataSource;
private Scheduler scheduler;

@AfterEach
void cleanUp() {
if (!Objects.isNull(scheduler)) {
scheduler.stop();
scheduler = null;
}
}

@Override
public DeadlineManager buildDeadlineManager(Configuration configuration) {
reCreateTable();
List<Task<?>> taskList = Collections.singletonList(DbSchedulerDeadlineManager.task());
scheduler = new SchedulerBuilder(dataSource, taskList)
.threads(2)
.pollingInterval(Duration.ofMillis(50L))
.build();
scheduler.start();
return DbSchedulerDeadlineManager
.builder()
.scheduler(scheduler)
.scopeAwareProvider(new ConfigurationScopeAwareProvider(configuration))
.serializer(TestSerializer.JACKSON.getSerializer())
.transactionManager(NoTransactionManager.INSTANCE)
.spanFactory(configuration.spanFactory())
.build();
}

@SuppressWarnings("Duplicates")
private void reCreateTable() {
Connection connection;
try {
connection = dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
try (PreparedStatement statement = connection.prepareStatement("drop table if exists scheduled_tasks;")) {
statement.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
try (PreparedStatement statement =
connection.prepareStatement(
"create table scheduled_tasks (\n"
+ " task_name varchar(40) not null,\n"
+ " task_instance varchar(40) not null,\n"
+ " task_data blob,\n"
+ " execution_time timestamp(6) not null,\n"
+ " picked BOOLEAN not null,\n"
+ " picked_by varchar(50),\n"
+ " last_success timestamp(6) null,\n"
+ " last_failure timestamp(6) null,\n"
+ " consecutive_failures INT,\n"
+ " last_heartbeat timestamp(6) null,\n"
+ " version BIGINT not null,\n"
+ " PRIMARY KEY (task_name, task_instance),\n"
+ ")")) {
statement.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

@org.springframework.context.annotation.Configuration
public static class Context {

@SuppressWarnings("Duplicates")
@Bean
public DataSource dataSource() {
JDBCDataSource dataSource = new JDBCDataSource();
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUser("sa");
dataSource.setPassword("");
return dataSource;
}
}
}
11 changes: 11 additions & 0 deletions messaging/pom.xml
Expand Up @@ -78,6 +78,17 @@
<artifactId>jobrunr</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.kagkarlsson</groupId>
<artifactId>db-scheduler</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>test</scope>
</dependency>

<!-- Query Handling -->
<dependency>
Expand Down