How can I safely reset Hangfire to a clean state?

前端 未结 3 807
礼貌的吻别
礼貌的吻别 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:05

    I ended up dropping the tables, at first the query did not work at all, it just kept going and nothing happened. I then used TRUNCATE TABLE [HangFire].[State] and it all worked like a charm after. Here is the script I used for Hangfire 1.5.6 with UseSqlServerStorage:

    GO
    PRINT N'Dropping [HangFire].[FK_HangFire_State_Job]...';
    
    
    GO
    ALTER TABLE [HangFire].[State] DROP CONSTRAINT [FK_HangFire_State_Job];
    
    
    GO
    PRINT N'Dropping [HangFire].[FK_HangFire_JobParameter_Job]...';
    
    
    GO
    ALTER TABLE [HangFire].[JobParameter] DROP CONSTRAINT [FK_HangFire_JobParameter_Job];
    
    
    GO
    PRINT N'Dropping [HangFire].[Schema]...';
    
    
    GO
    DROP TABLE [HangFire].[Schema];
    
    
    GO
    PRINT N'Dropping [HangFire].[Job]...';
    
    
    GO
    DROP TABLE [HangFire].[Job];
    
    
    GO
    PRINT N'Dropping [HangFire].[State]...';
    
    
    GO
    DROP TABLE [HangFire].[State];
    
    
    GO
    PRINT N'Dropping [HangFire].[JobParameter]...';
    
    
    GO
    DROP TABLE [HangFire].[JobParameter];
    
    
    GO
    PRINT N'Dropping [HangFire].[JobQueue]...';
    
    
    GO
    DROP TABLE [HangFire].[JobQueue];
    
    
    GO
    PRINT N'Dropping [HangFire].[Server]...';
    
    
    GO
    DROP TABLE [HangFire].[Server];
    
    
    GO
    PRINT N'Dropping [HangFire].[List]...';
    
    
    GO
    DROP TABLE [HangFire].[List];
    
    
    GO
    PRINT N'Dropping [HangFire].[Set]...';
    
    
    GO
    DROP TABLE [HangFire].[Set];
    
    
    GO
    PRINT N'Dropping [HangFire].[Counter]...';
    
    
    GO
    DROP TABLE [HangFire].[Counter];
    
    
    GO
    PRINT N'Dropping [HangFire].[Hash]...';
    
    
    GO
    DROP TABLE [HangFire].[Hash];
    
    
    GO
    PRINT N'Dropping [HangFire].[AggregatedCounter]...';
    
    
    GO
    DROP TABLE [HangFire].[AggregatedCounter];
    
    
    GO
    PRINT N'Dropping [HangFire]...';
    
    
    GO
    DROP SCHEMA [HangFire];
    
    
    GO
    PRINT N'Update complete.';
    
    
    GO
    

提交回复
热议问题