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

Register and execute compensations #118

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Register and execute compensations #118

wants to merge 3 commits into from

Conversation

slinkydeveloper
Copy link
Contributor

Fix #95

This PR prototypes compensations, that is a way to register closures to be executed in case of a failure. Some properties:

  • Compensations are executed only when the thrown error is terminal (thus only when we're going to write out a OutputStreamEntry).
  • Compensations are run in the same context/thread of the handler, similarly to sideEffect closures. This simplifies the threading model for the user.
  • Only non-completable journal entries are allowed within compensations, that is side effect, clear/set state, complete awakeable, one way calls.
  • Compensations are executed in the reverse order used to set them

Example:

// Register the compensation
ctx.compensate(() -> ctx.set(StateKey.of("message", TypeTag.STRING_UTF8), "none"));
// Do some operation
GreetingResponse greetingResponse = ctx.call(GreeterGrpc.getGreetMethod(), greetingRequest("Francesco")).await();
// If the call fails, the compensation above will be executed

@github-actions
Copy link
Contributor

Unit Test Results

275 tests  +14   275 ✔️ +14   13s ⏱️ -1s
  28 suites +  2       0 💤 ±  0 
  28 files   +  2       0 ±  0 

Results for commit 15dffa6. ± Comparison against base commit 8223cd6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce error-defer handler / sagas / compensations
1 participant