We need to change the way our program formats recurring job identifiers to eliminate a bug. Ideally, we could update the existing identifiers to the new format to avoid creating duplicates when calling AddOrUpdate(). We attempted to simply update the Value field of the HangFire.Set table, but this caused a null reference exception when accessing the recurring jobs page of the Dashboard.
Is there any way to change the identifier of a recurring job after it has been created?
Here is the error I’m getting after updating the database table.
And the SQL script looks something like this:
UPDATE [ReservationDisplaySystem].[HangFire].[Set]
SET [Value] = LEFT([Value], CHARINDEX(‘-’, [Value], 6)-1)
WHERE [Value] LIKE ‘Lab-%-%’
You also need to update Hash table so recurring job parameters are correctly resolved. Something like:
UPDATE HangFire.Set
SET Value = LEFT(Value, CHARINDEX('-', Value, 6) - 1)
WHERE Key = 'recurring-jobs'
AND Value LIKE 'Lab-%-%'
UPDATE Hangfire.Hash
SET Key = LEFT(Key, CHARINDEX('-', Key, 20) - 1)
WHERE Key LIKE 'recurring-job:Lab-%-%'
But it would still be easier just to drop and re-create them. After all, applications usually add-or-update their recurring jobs at startup, so it would be just a matter of restarting the app.
Thanks for the reply, that seems to have worked! If I encounter problems later I’ll try your other suggestion.