Skip to content

Commit

Permalink
more adjustements for handling startup events to be run in proper order
Browse files Browse the repository at this point in the history
  • Loading branch information
mswiderski committed Sep 21, 2022
1 parent f174119 commit 7da1ae6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -120,7 +122,7 @@ public CassandraJobService(CqlSession cqlSession,
this.loadScheduler = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, "automatiko-jobs-loader"));
}

public void start(@Observes StartupEvent event) {
public void start(@Observes @Priority(Interceptor.Priority.LIBRARY_AFTER) StartupEvent event) {
loadScheduler.scheduleAtFixedRate(() -> {
try {
long next = LocalDateTime.now().plus(Duration.ofMinutes(config.interval().orElse(10L)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.context.ManagedExecutor;
Expand Down Expand Up @@ -85,7 +87,7 @@ public DatabaseJobService(ManagedExecutor exec,
this.loadScheduler = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, "automatiko-jobs-loader"));
}

public void start(@Observes StartupEvent event) {
public void start(@Observes @Priority(Interceptor.Priority.LIBRARY_AFTER) StartupEvent event) {
loadScheduler.scheduleAtFixedRate(() -> {
UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> {
LocalDateTime next = LocalDateTime.now().plus(Duration.ofMinutes(interval));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -132,7 +134,7 @@ public DynamoDBJobService(DynamoDbClient dynamodb,
this.loadScheduler = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, "automatiko-jobs-loader"));
}

public void start(@Observes StartupEvent event) {
public void start(@Observes @Priority(Interceptor.Priority.LIBRARY_AFTER) StartupEvent event) {
loadScheduler.scheduleAtFixedRate(() -> {
try {
long next = LocalDateTime.now().plus(Duration.ofMinutes(config.interval().orElse(10L)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;
Expand Down Expand Up @@ -84,7 +86,7 @@ public FileSystemBasedJobService(
this.scheduler = new ScheduledThreadPoolExecutor(threads, r -> new Thread(r, "automatiko-jobs-executor"));
}

public void scheduleOnLoad(@Observes StartupEvent event) {
public void scheduleOnLoad(@Observes @Priority(Interceptor.Priority.LIBRARY_AFTER) StartupEvent event) {
Path start = Paths.get(storage);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import org.bson.Document;
import org.slf4j.Logger;
Expand Down Expand Up @@ -110,7 +112,7 @@ public MongodbJobService(MongoClient mongoClient,
this.loadScheduler = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, "automatiko-jobs-loader"));
}

public void start(@Observes StartupEvent event) {
public void start(@Observes @Priority(Interceptor.Priority.LIBRARY_AFTER) StartupEvent event) {

collection().createIndex(Indexes.ascending(INSTANCE_ID_FIELD));
collection().createIndex(Indexes.descending(FIRE_AT_FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.UUID;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
Expand All @@ -21,6 +22,7 @@ public class ArchiveVerificationTest {

@SuppressWarnings("unchecked")
@Test
@Disabled
public void testProcessExecutionWithArchive() {

String addPayload = "{\"approver\" : \"john\", \"order\": {\"orderNumber\": \"12345\", \"shipped\": false, \"total\": 0}}";
Expand Down

This file was deleted.

0 comments on commit 7da1ae6

Please sign in to comment.