Skip to content

Commit

Permalink
refactor(TriggerContext): Add executed state
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Dec 14, 2023
1 parent 5ba1d7e commit e3e6ff2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
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));
}

}

0 comments on commit e3e6ff2

Please sign in to comment.