0

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?

2
  • Wait, SQL Server v.7? As in v7.0 released in 1998?
    – squillman
    Oct 11, 2022 at 12:08
  • 1
    My fault, I meant Hangfire v.7. I've edited it. Thank you Oct 11, 2022 at 12:16

1 Answer 1

0

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:

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: State record

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.