Skip to content

Commit

Permalink
Scheduled methods - mark vertx context as safe
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Apr 29, 2022
1 parent 5e8584f commit cc4aef5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
import io.quarkus.scheduler.common.runtime.StatusEmitterInvoker;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
import io.quarkus.scheduler.runtime.SchedulerRuntimeConfig;
import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle;
import io.smallrye.common.vertx.VertxContext;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;

Expand Down Expand Up @@ -555,20 +557,22 @@ static class InvokerJob implements Job {
}

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
if (trigger.invoker != null) { // could be null from previous runs
if (trigger.invoker.isBlocking()) {
try {
trigger.invoker.invoke(new QuartzScheduledExecution(trigger, context));
trigger.invoker.invoke(new QuartzScheduledExecution(trigger, jobExecutionContext));
} catch (Exception e) {
throw new JobExecutionException(e);
}
} else {
VertxContext.getOrCreateDuplicatedContext(vertx).runOnContext(new Handler<Void>() {
Context context = VertxContext.getOrCreateDuplicatedContext(vertx);
VertxContextSafetyToggle.setContextSafe(context, true);
context.runOnContext(new Handler<Void>() {
@Override
public void handle(Void event) {
try {
trigger.invoker.invoke(new QuartzScheduledExecution(trigger, context));
trigger.invoker.invoke(new QuartzScheduledExecution(trigger, jobExecutionContext));
} catch (Exception e) {
// already logged by the StatusEmitterInvoker
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.quarkus.scheduler.common.runtime.SkipPredicateInvoker;
import io.quarkus.scheduler.common.runtime.StatusEmitterInvoker;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle;
import io.smallrye.common.vertx.VertxContext;
import io.vertx.core.Context;
import io.vertx.core.Handler;
Expand Down Expand Up @@ -319,6 +320,7 @@ public void run() {
}
} else {
Context context = VertxContext.getOrCreateDuplicatedContext(vertx);
VertxContextSafetyToggle.setContextSafe(context, true);
context.runOnContext(new Handler<Void>() {
@Override
public void handle(Void event) {
Expand Down

0 comments on commit cc4aef5

Please sign in to comment.