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

Support for Reactive Interceptors or Reactive Operations inside Interceptors #1168

Open
vedantshetty opened this issue Oct 11, 2024 · 0 comments
Labels
status/need-triage Team needs to triage and take a first look

Comments

@vedantshetty
Copy link

vedantshetty commented Oct 11, 2024

I have been playing around with the state machine and have managed to utilise it to run as a workflow management system, where the state machine would persist the extended state to a database after a state transition using a preStateChange hook

    private class StateChangeInterceptor extends StateMachineInterceptorAdapter<S, E> {

        @Override
        public void preStateChange(State<S, E> state, Message<E> message,
                                   Transition<S, E> transition, StateMachine<S, E> stateMachine,
                                   StateMachine<S, E> rootStateMachine) {
          var data = getData(state, message);
           reactiveRepo.save(data).subscribe();
        }
    }

However, I noticed that the DB write needs to be blocking otherwise actions which are supposed to run after state change tend to trigger

        .state(ServiceRequestState.APPROVED,  triggerActions())

// This will run before the state change leading to weird issues like the state context being in an inconsistent stage
  private Collection<? extends Action<WorkflowState, WorkflowEvent>> triggerActions() {
    return List.of(
        Actions.errorCallingAction(notifyCustomer, handleNotificationFailure),
        Actions.errorCallingAction(logAnalytics, loggingFailure)
    );
  }

Currently my way around this is to provide an indication of the DB write being completed using the Workflow Extended State but would love to understand if there was a better way

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Oct 11, 2024
@vedantshetty vedantshetty changed the title Reactive Interceptors Support for Reactive Interceptors or Reactive Actions inside Interceptors Oct 11, 2024
@vedantshetty vedantshetty changed the title Support for Reactive Interceptors or Reactive Actions inside Interceptors Support for Reactive Interceptors or Reactive Operations inside Interceptors Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

1 participant