HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.43k stars 1.7k forks source link

StateHistoryDto.StateName is "Processing" in ContinueJobWith #2430

Open marcinjahn opened 3 months ago

marcinjahn commented 3 months ago

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?