2

I need to add some additional columns in hangfire tables. I don't know how can I add additional columns to hangfire tables.

Can anyone guide me on how can I add additional columns in hangfire tables and how hangfire will insert values for these newly added columns?

I'm using hangfire fire and forget jobs and for storage, I'm using the SQL server. I have installed hangfire in my .net Core project using the NuGet package manager.

Rafaqat Ali
  • 676
  • 7
  • 26

1 Answers1

0

For future visitors, there are two options to achieve this:

A) create a new table using your own preferred method that has a jobId column, and store the jobId in that table with your additional information when the job is scheduled or called.

you'll have the most flexibility with this option as you own the code. Note: careful that hangfire automatically removes succeeded jobs (default retention period is 24hours), so your table might get out of sync.

B) override hangfire storage and process

  1. create a new class YourCustomSqlServerStorage that inherits the SqlServerStorage see github link
  2. create an extension to initialize this class instead of the hangfire useSqlServerStorage github link , in this extension you only want to replace the initialization of SqlServerStorage with YourCustomSqlServerStorage
  3. in your program.cs call the new extension method instead of calling UseSqlServerStorage
  4. in YourCustomSqlServerStorage in all constructors, see how hangfire is calling the Initialize() method which in turn is executing the install.sql script github link, you want to imitate it's behavior to create your own tables.

the above is only for table creation, you'll basically have to override classes based on your need, hangfire executes raw SQL queries so your new columns won't be used unless you override and update the queries accordingly.

I wouldn't recommend the second option for many reasons other than the following: you'll have to override many classes which some of them are internal, plus it's tedious to read and update the code and queries that hangfire actually executes, and if you have to update the package then things might go wrong again.

Modar Na
  • 873
  • 7
  • 18