You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to implement a custom IBackgroundJobStateChanger to intercept and log every state change in my Hangfire jobs. My goal is to execute specific logic every time a job's state changes (e.g., from Enqueued to Processing, or from Processing to Succeeded, same with failed).
Despite following the standard procedure for replacing the default IBackgroundJobStateChanger with a custom implementation, I'm observing that my custom state changer is not being invoked consistently for every state change.
Current Implementation
I've configured my custom IBackgroundJobStateChanger as follows in my Program.cs:
publicclass CustomBackgroundJobStateChanger(ILogger<CustomBackgroundJobStateChanger> iLogger,[NotNull] IBackgroundJobStateChanger inner):IBackgroundJobStateChanger{privatereadonlyIBackgroundJobStateChanger_inner=inner??thrownew ArgumentNullException(nameof(inner));public IState ChangeState(StateChangeContextcontext){
iLogger.LogInformation("Entering ChangeState in CustomBackgroundJobStateChanger");
iLogger.LogError("ChangeState {ContextBackgroundJobId} to {ContextNewState}", context.BackgroundJobId, context.NewState);varresult= _inner.ChangeState(context);
iLogger.LogInformation("Exiting ChangeState in CustomBackgroundJobStateChanger");returnresult;}}
Questions
Are there known issues or limitations with IBackgroundJobStateChanger in Hangfire 1.8.7 that could prevent a custom implementation from being invoked as expected?
Is there a recommended approach or alternative method to ensure that custom logic can be executed reliably on every state change in Hangfire jobs?
Thank you for your assistance and any guidance you can provide on this issue.
The text was updated successfully, but these errors were encountered:
Environment
Issue
I am attempting to implement a custom
IBackgroundJobStateChanger
to intercept and log every state change in my Hangfire jobs. My goal is to execute specific logic every time a job's state changes (e.g., from Enqueued to Processing, or from Processing to Succeeded, same with failed).Despite following the standard procedure for replacing the default
IBackgroundJobStateChanger
with a custom implementation, I'm observing that my custom state changer is not being invoked consistently for every state change.Current Implementation
I've configured my custom
IBackgroundJobStateChanger
as follows in myProgram.cs
:CustomBackgroundJobStateChanger Implementation
Questions
IBackgroundJobStateChanger
in Hangfire 1.8.7 that could prevent a custom implementation from being invoked as expected?Thank you for your assistance and any guidance you can provide on this issue.
The text was updated successfully, but these errors were encountered: