How can I safely reset Hangfire to a clean state?

前端 未结 3 738
礼貌的吻别
礼貌的吻别 2020-12-30 03:28

I have a server with Hangfire installed. I haven\'t checked it for a while and it seems one recurring job has gone rogue. It stopped working and then it has stacked up with

3条回答
  •  说谎
    说谎 (楼主)
    2020-12-30 04:10

    I've seen a pretty interesting solution here

    TRUNCATE TABLE [HangFire].[AggregatedCounter]
    TRUNCATE TABLE [HangFire].[Counter]
    TRUNCATE TABLE [HangFire].[JobParameter]
    TRUNCATE TABLE [HangFire].[JobQueue]
    TRUNCATE TABLE [HangFire].[List]
    TRUNCATE TABLE [HangFire].[State]
    DELETE FROM [HangFire].[Job]
    DBCC CHECKIDENT ('[HangFire].[Job]', reseed, 0)
    UPDATE [HangFire].[Hash] SET Value = 1 WHERE Field = 'LastJobId'
    

    This basically truncates all the tables and resets the seeding for the Job table (reseting job id's)

    I think it's also worth mentioning that it is good and sensible practice to stop your application and make sure the worker processes have cleared up on your server before running any scripts

提交回复
热议问题