Skip to content

Commit

Permalink
Enforce rollback in case of testing for task fails
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Jul 31, 2024
1 parent cba5dea commit 195d677
Showing 1 changed file with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.springframework.context.ApplicationEvent;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class Camunda8TransactionProcessor {

Expand Down Expand Up @@ -109,17 +107,13 @@ public void processPreCommit(
// if the task is completed or cancelled, then the tx is rolled back
if ((e instanceof ClientStatusException clientStatusException)
&& (clientStatusException.getStatus().getCode() == Status.NOT_FOUND.getCode())) {
logger.warn(
"Will rollback because job was already completed/cancelled! Tested with command '{}‘ giving status 'NOT_FOUND'",
event.description.get());
throw new RuntimeException(
"Will rollback because job was already completed/cancelled! Test-command giving status 'NOT_FOUND':\n"
+ event.description.get());
} else {
logger.warn(
"Will rollback because testing for job '{}' failed!",
event.description.get(),
e);
}
if (TransactionSynchronizationManager.isActualTransactionActive()) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException(
"Will rollback because testing for job '{}' failed! Test-command:\n"
+ event.description.get());
}
}

Expand Down

0 comments on commit 195d677

Please sign in to comment.