I’m wondering if such a feature is supported somehow. Consider this scenario:
I’m importing a large CSV file to a database in ImportCSV job.
At the same time, I want to schedule a job to be executed at a later time to do something with the data I’m importing, let’s call it ProcessUsers. This job should be executed only if the parent job (ImportCSV) has been completed successfully AND the scheduled date has occurred or passed.
The Continuations API doesn’t seem to support this, unless I’m missing something.
That’s an interesting approach but it doesn’t seem to work:
Failed
Can not change the state to 'Enqueued': target method was not found.
Newtonsoft.Json.JsonSerializationException
Unable to find a constructor to use for type System.Linq.Expressions.Expression`1[System.Func`1[System.Threading.Tasks.Task]]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute
I guess it can’t serialize the parameters passed to the Schedule method…
After exploring the source code a bit I figured out a nice solution.
The idea is to use the underlying BackgroundClientJob object which exposes some nice extra features:
var hangfireClient = new BackgroundJobClient();
hangfireClient.ContinueWith(parentJobId,
() =>
DoDelayedBackgroundJob(),
new ScheduledState(executionDate));