We have been using Hangfire v.7 with SQL Server for a long time and have a lot of delayed jobs. I want to find those scheduled to run in a specific period (e.g. from 2030-01-01T01:00:00 to 2030-01-01T03:00:00) and postpone them for N hours. I assume there are some columns in the Hangfire database that specify the execution time of each job. Is it valid? How can I change the execution time of delayed jobs via a SQL script?
I've read the Hangfire source code and followed the process starting from BackgroundJob.Schedule
, which is the API method for creating a new delayed job, until the changes it commits to the DB. This is the DB schema:
Every delayed job has a record in the [Job]
table and its execution data is saved in the [State]
table. An unexecuted scheduled job has a state record like this:
The [Data]
column has scheduling details in JSON format. The value of EnqueueAt
is when the job is supposed to start execution in the UNIX time stamp. For SQL Server v.16 or higher a script like this can be useful:
UPDATE [State]
SET JSON_MODIFY([Data], '$.EnqueueAt', '0000000000000'/*put your time stamp here*/)
WHERE condition