Hangfire.EntityFrameworkCore icon indicating copy to clipboard operation
Hangfire.EntityFrameworkCore copied to clipboard

Error removing expired jobs with parameters

Open mgparedes-hiberus opened this issue 1 year ago • 0 comments

Hi,

I detect an error when testing library. If jobs are expired, this fails because HangfireJobParameter and HangFireState has entries with JobId related.

Error:

`23503: update or delete on table "HangfireJob" violates foreign key constraint "FK_HangfireJobParameter_HangfireJob_JobId" on table "HangfireJobParameter"

DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.`

A possible solution is to put this on line 73 of the ExpirationManager.cs file:

// Trying remove HangfireJobParameter from expired jobs
context.Set<HangfireJobParameter>().RemoveRange(
          context.Set<HangfireJobParameter>().Where(x => expiredEntityIds.Contains(x.JobId)));

// Trying remove HangfireState from expired jobs
                context.Set<HangfireState>().RemoveRange(
                    context.Set<HangfireState>().Where(x => expiredEntityIds.Contains(x.JobId)));

Thanks

mgparedes-hiberus avatar Apr 13 '23 07:04 mgparedes-hiberus