Search code examples
c#.netasp.net-mvchangfirerecurring

Recurring Job with delay time


I'm using Hangfire version "1.6.8". I want create recurring job with Cron.Daily after certain DateTime . Is that possible to create recurring job with delay time ?

Thanks in advance


Solution

  • I can't think of any particularly clean way of doing this.

    You could explore the avenue of using a hangfire Scheduled job to create the RecurringJob:

    new BackgroundJobClient().Schedule(() => Hangfire.RecurringJob.AddOrUpdate(() => Console.WriteLine("Hello World"), Cron.Daily()), startDateTime)
    

    Which could be set to run the Scheduled job shortly before the first expected run time of the Recurring Job, and thus hangfire runs the schedule and creates the job itself. I haven't actually ever tried to do this, so please do test it (and let me know how it goes).