Hangfire - Rescheduling Scheduled jobs
Asked Answered
V

0

6

To reschedule scheduled jobs I am currently deleting the previous job and then scheduling a new one within a transaction so if the schedule fails it rolls back the delete:

using (var transaction = new TransactionScope(TransactionScopeOption.Required))
{
    BackgroundJob.Delete(jobId);
    BackgroundJob.Schedule(...);
}

This involves keeping storing the original arguments somewhere so I can reschedule with the original args.

I was wondering whether there was any ramifications to doing the following instead:

new BackgroundJobClient().ChangeState(jobId, new ScheduledState(timespan), ScheduledState.StateName);

This way there is no need to keep the original job arguments around and also is transactional.

Vange answered 23/6, 2021 at 23:50 Comment(1)
it appears, you'd lose audit trail of when your jobs ran in the past this way?Flibbertigibbet

© 2022 - 2024 — McMap. All rights reserved.