-
Notifications
You must be signed in to change notification settings - Fork 0
Cancel a task trigger
Paul Sterl edited this page Mar 9, 2025
·
3 revisions
In general any trigger/task which is not running can be canceled. As soon it is in the running state it cannot be canceled anymore.
As soon a task is triggered, a task may decide to cancel or to fail itself. Both will suppress any outstanding retries of the retry strategy.

@Test
void tesCancelRunningTrigger() {
// GIVEN
TaskId<String> taskId = taskService.replace("foo-cancel", c -> {
throw new CancelTaskException(c);
});
var key1 = subject.queue(taskId.newTrigger().build()).getKey();
// WHEN
assertThat(runNextTrigger()).isPresent();
// THEN
assertThat(historyService.findLastKnownStatus(key1).get().status()).isEqualTo(TriggerStatus.CANCELED);
// AND
assertThat(events.stream(TriggerCanceledEvent.class).count()).isOne();
}
@Test
void tesFailRunningTriggerNoRetry() {
// GIVEN
TaskId<String> taskId = taskService.replace("foo-fail", c -> {
throw new FailTaskNoRetryException(c);
});
var key1 = subject.queue(taskId.newTrigger().build()).getKey();
// WHEN
assertThat(runNextTrigger()).isPresent();
// THEN
assertThat(historyService.findLastKnownStatus(key1).get().status()).isEqualTo(TriggerStatus.FAILED);
// AND
assertThat(events.stream(TriggerFailedEvent.class).count()).isOne();
}