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

OnStateApplied is invoked before database transaction #2502

Open
robin-83 opened this issue Mar 3, 2025 · 0 comments
Open

OnStateApplied is invoked before database transaction #2502

robin-83 opened this issue Mar 3, 2025 · 0 comments

Comments

@robin-83
Copy link

robin-83 commented Mar 3, 2025

Hello,
I have a custom IApplyStateFilter that is used in all my Hangfire servers. In the OnStateApplied implementation I send a SignalR notification to registered clients. Sometimes a client cannot receive the job (and associated data) as the job is not in the expected state, when this is implemented like this:
JobStorage.Current.GetMonitoringApi().SuccededJobs.

This is because OnStateApplied is invoked before the database transaction is executed (this is also documented somewhere). Persistance is done by the CoreStateMachine after OnStateApplied:

return _innerStateMachine.ApplyState(context);

The only way to notify my clients after the transaction seems to require custom IStateHandler (each corresponding to a Hangfire built-in state) which invoke a a custom OnStatePersisted Command in the Apply method.

Is this the right approach or do you see a better solution?

Best regards

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

No branches or pull requests

1 participant