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

Feature/add trigger state executed #90

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected final void onMisfire(@NotNull TriggerTransitionContext triggerContext)

protected final void onResult(@NotNull ExecutionContext<OUT> executionContext, @Nullable Throwable asyncCause) {
final ExecutionContextInternal<OUT> ctx = (ExecutionContextInternal<OUT>) executionContext;
final TriggerTransitionContext triggerContext = ctx.triggerContext();
final TriggerTransitionContext triggerContext = TriggerContextFactory.executed(ctx.triggerContext());
final Instant finishedAt = state.markFinished(triggerContext.tick());
log(finishedAt, "On result", triggerContext.tick(), ctx.round());
if (asyncCause instanceof TimeoutException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ private TriggerContextFactory() { }
return transition(ctx, TriggerStatus.READY, null, null);
}

/**
* Transition trigger context to {@link TriggerStatus#EXECUTED} state.
*
* @param ctx the current trigger context
*/
public static @NotNull TriggerTransitionContext executed(@NotNull TriggerTransitionContext ctx) {
return transition(ctx, TriggerStatus.EXECUTED, null, null);
}

/**
* Transition trigger context to {@link TriggerStatus#SKIPPED} state.
*
* @param ctx the current trigger context
* @param reason the transition reason
*/
public static @NotNull TriggerTransitionContext skip(@NotNull TriggerTransitionContext ctx, @NotNull String reason) {
public static @NotNull TriggerTransitionContext skip(@NotNull TriggerTransitionContext ctx,
@NotNull String reason) {
return transition(ctx, TriggerStatus.SKIPPED, reason, null);
}

Expand All @@ -105,7 +115,8 @@ private TriggerContextFactory() { }
* @param ctx the current trigger context
* @param reason the transition reason
*/
public static @NotNull TriggerTransitionContext stop(@NotNull TriggerTransitionContext ctx, @Nullable String reason) {
public static @NotNull TriggerTransitionContext stop(@NotNull TriggerTransitionContext ctx,
@Nullable String reason) {
return transition(ctx, TriggerStatus.STOPPED, reason, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ enum TriggerStatus {
* Identify the trigger is satisfied every predicate then ready to execute the task
*/
READY,
/**
* Identify the trigger is already run
*/
EXECUTED,
/**
* Identify the trigger is skipped to execute the task
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public interface TriggerContext extends HasTriggerType {
*/
default boolean isReady() { return TriggerStatus.READY == condition().status(); }

/**
* Check whether the trigger is executed or not.
*/
default boolean isExecuted() { return TriggerStatus.EXECUTED == condition().status(); }

/**
* Check whether the trigger is skipped or not.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onEach(@NotNull ExecutionResult<OUT> result) {
Assertions.assertNotNull(result.firedAt());
Assertions.assertNotNull(result.triggeredAt());
Assertions.assertNotNull(result.triggerContext());
Assertions.assertTrue(result.triggerContext().isReady());
Assertions.assertTrue(result.triggerContext().isExecuted());
Assertions.assertNotNull(result.executedAt());
Assertions.assertNotNull(result.finishedAt());
Assertions.assertNull(result.rescheduledAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ void test_event_trigger_can_handle_msg_with_various_datatype(Vertx vertx, VertxT
.setTask(NoopTask.create(totalEvent))
.build()
.start();
data.forEach(d -> {
vertx.eventBus().publish(address, d);
});
data.forEach(d -> vertx.eventBus().publish(address, d));
}

}
Loading