HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.31k stars 1.69k forks source link

Question: Rescheduling Scheduled jobs #1882

Open kimsagro1 opened 3 years ago

kimsagro1 commented 3 years ago

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 storing the original arguments somewhere so I can reschedule with the original arguments.

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.

Thoughts?

courtzzz commented 3 years ago

We have the same issue working on Azure Devops backup MVP - we have scheduled backup jobs which the user can then change. Is it better to change state? We're really in testing at the moment but when we go live will be good to know.

kimsagro1 commented 3 years ago

@odinserj Are you able to confirm?