Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

StateHistoryDto.StateName is "Processing" in ContinueJobWith

Open marcinjahn opened this issue 6 months ago • 0 comments

When I set up continuation of my job, I'd expect JobStorage.Current.GetMonitoringApi().JobDetails.History to contain a state where the job is "Succeeded" (in happy path). However, it randomly happens that the latest entry there is "Processing". Is it expected?

Here's simplified version of my code:

var state = new EnqueuedState("my-queue");
var jobId = client.Create<MyJob>(
    job => job.Run(cancellationToken),
    state
);

client.ContinueJobWith(
    jobId,
    () => DoSomething(jobId),
    state
);

public async Task DoSomething(sting jobId)
{
    var jobDetails = JobStorage.Current.GetMonitoringApi().JobDetails(jobId);

    var lastJobState = jobDetails.History.OrderByDescending(state => state.CreatedAt).First();

    _logger.log(lastJobState.StateName); // logs "Processing" for some jobs
}

If I'm doing something wrong, what's the proper way to get the job's state and timestamp of its finished execution?

marcinjahn avatar Aug 06 '24 12:08 marcinjahn