How can I add date to the HangFire task? For example, this code adds 7 days:
BackgroundJob.Schedule(
() => Console.WriteLine("Reliable!"),
TimeSpan.FromDays(7));
But what if I need to run task in specific date?
How can I add date to the HangFire task? For example, this code adds 7 days:
BackgroundJob.Schedule(
() => Console.WriteLine("Reliable!"),
TimeSpan.FromDays(7));
But what if I need to run task in specific date?
If the year doesn't matter, you can use cron expression for this purpose. Most default cron implementations (like NCrontab used by Hangfire) don't include the year field.
BackgroundJob.Schedule(
() => Console.WriteLine("Reliable!"),
"30 4 27 6 *");
This job will be executed at 4.30am on the 27th of June every year.
As the developer answerd my question here, You can simply use the date instead of day(s).
BackgroundJob.Schedule(
() => Console.WriteLine("Reliable!"),
new DateTime(2015, 08, 05, 12, 00, 00));
For 05/08/2015 at 00:00.
Jerry's answer is true for RecurringJobs
RecurringJob.Schedule(
() => Console.WriteLine("Reliable!"),
"00 00 05 8 *");
which will run every year on 05/08 at 00:00
Schedule
method in RecurringJob
class. –
Idyllic Use Cron.Yearly()
to run it once a year at certain date-time:
// Will run on 4th of July @ 8 AM UTC every year
BackgroundJob.Schedule(
() => Console.WriteLine("Happy 4th of July!"),
Cron.Yearly(7, 4, 8, 0));
© 2022 - 2024 — McMap. All rights reserved.