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 retries resulting in a complete lock it seems.
I would like to clear my database and start over. Can i just delete the data from all tables or should I drop the tables and let Hangfire recreate them for me? Am I risking anything by doing this?
Hangfire.State using entire Azure Basic database 2GB of space.
SlidingInvisibilityTimeout is used to indicate how long a BackgroundJob execution is allowed to run for without status change (success/failure) before Hangfire decides the BackgroundJob execution was not successful and needs to be made visible to the HangfireServer for processing again.
You can clear all hangfire jobs by Truncating all the hangfire tables and reset the seeding for the Job table. (Resetting job id's) TRUNCATE TABLE [HangFire].
Reentrancy means that a method can be interrupted in the middle of its execution and then safely called again. The interruption can be caused by many different things (i.e. exceptions, server shut-down), and Hangfire will attempt to retry processing many times. You can have many problems, if you don’t prepare your jobs to be reentrant.
When Hangfire encounters external exception that occurred during the job performance, it will automatically try to change its state to the Failed one, and you always can find this job in the Monitor UI (it will not be expired unless you delete it explicitly).
Our hangfire sql database has grown to 30GB. We cannot reset our db to new due to a lot of scheduled jobs that we want to keep. Has anyone come up with scripts to purge old completed/failed jobs? thanks. Try reclaiming white space / re-index table in online mode (or offline mode scheduled for faster performance). Sorry, something went wrong.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With