Skip to content

Commit

Permalink
Merge pull request #19904 from geoand/#19900
Browse files Browse the repository at this point in the history
Fix issue with skip predicates in scheduled methods
  • Loading branch information
geoand authored Sep 3, 2021
2 parents aba0907 + 3614947 commit 4e5ce8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class SchedulerProcessor {
static final DotName SCHEDULED_NAME = DotName.createSimple(Scheduled.class.getName());
static final DotName SCHEDULES_NAME = DotName.createSimple(Scheduled.Schedules.class.getName());
static final DotName SKIP_NEVER_NAME = DotName.createSimple(Scheduled.Never.class.getName());
static final DotName SKIP_PREDICATE = DotName.createSimple(Scheduled.SkipPredicate.class.getName());

static final Type SCHEDULED_EXECUTION_TYPE = Type.create(DotName.createSimple(ScheduledExecution.class.getName()),
Kind.CLASS);
Expand Down Expand Up @@ -466,4 +467,9 @@ private Throwable validateScheduled(CronParser parser, AnnotationInstance schedu
return null;
}

@BuildStep
UnremovableBeanBuildItem unremoveableSkipPredicates() {
return new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanTypeExclusion(SKIP_PREDICATE));
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.quarkus.scheduler.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import javax.enterprise.event.Observes;
import javax.inject.Singleton;
Expand Down Expand Up @@ -44,17 +46,25 @@ public void testExecution() {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}

assertTrue(OtherIsDisabled.TESTED.get());
assertEquals(0, Jobs.OTHER_COUNT.get());
}

static class Jobs {

static final CountDownLatch COUNTER = new CountDownLatch(1);
static final AtomicInteger OTHER_COUNT = new AtomicInteger(0);

@Scheduled(identity = "foo", every = "1s", skipExecutionIf = IsDisabled.class)
void doSomething() throws InterruptedException {
COUNTER.countDown();
}

@Scheduled(identity = "other-foo", every = "1s", skipExecutionIf = OtherIsDisabled.class)
void doSomethingElse() throws InterruptedException {
OTHER_COUNT.incrementAndGet();
}
}

@Singleton
Expand All @@ -77,4 +87,17 @@ void onSkip(@Observes SkippedExecution event) {
}

}

@Singleton
public static class OtherIsDisabled implements Scheduled.SkipPredicate {

static final AtomicBoolean TESTED = new AtomicBoolean(false);

@Override
public boolean test(ScheduledExecution execution) {
TESTED.set(true);
return true;
}

}
}

0 comments on commit 4e5ce8a

Please sign in to comment.