Skip to content

OnStateApplied is invoked before database transaction #2502

Open
@robin-83

Description

@robin-83

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions