HangfireIO / HangfireIO/Hangfire

OnStateApplied event derived from IApplyStateFilter, does not show the correct status change in case of a Success/Failure.

Open
#1,009 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

I am using hangfire 1.6.5 version, this is my code.

public async void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
var backgroundJob = context.BackgroundJob?.Job?.Args?.Any(x => x.GetType() == typeof(BackgroundJob));
if (backgroundJob == false) return;
var job = context.BackgroundJob?.Job?.Args?.First(x => x.GetType() == typeof(BackgroundJob)) as BackgroundJob;
if (job == null) return;
var jobid = job.Id;

switch (context.NewState?.Name)
{
case "Succeeded":
//Log something
break;

case "Failed":
//Log Something
break;
}
}
This event is supposed to hit whenever the hangfire status changes, so when I debug on local machine, the status is always enqueued, so it never goes inside the switch obviously, but the job is actually succeeded. The same thing intermittently happens on the server as well. I had tried updating the hangfire to latest version of 1.6.17 but still same.

what could be the issue ?
TIA.

Contributor guide

Open the contributing guide

Research direction

Start with the supplied OnStateApplied implementation and the IApplyStateFilter contract, then reproduce a job that moves from Enqueued to Succeeded or Failed while inspecting context.NewState. Done means the filter observes the correct terminal state consistently; no repository files or tests are named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.