I wrote a script that cleans up the job table, but sadly it doesn’t clean it up - it fights with the running web-app for escalating locks - even running the script for 40mins doesn’t remove the records, even though SQL says it’s done and affected X rows.
The table has somewhere around 18.000 records, of which I’d like to delete everything older than 7 days.
DECLARE @DaysAgo DATETIME;
DECLARE @RowsDeleted INT = 1, @counter INT = 1;
SET @DaysAgo = DateAdd(DD,-7,GETDATE());
WHILE (@RowsDeleted > 0)
DELETE top(10) FROM [HangFire].[Job] WHERE CreatedAt < @DaysAgo;
SELECT @RowsDeleted = @@ROWCOUNT, @counter += 1;
IF @counter % 10 = 0
Anyone knows of a solution that doesn’t involve shutting down hangfire?
I’m considering to truncate the table, because we don’t really need the history - but it’d be a plus if we could keep records, younger than 7 days.