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
- create a new class
YourCustomSqlServerStorage
that inherits the SqlServerStorage
see github link
- 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
- in your
program.cs
call the new extension method instead of calling UseSqlServerStorage
- 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.