Skip to content

Instantly share code, notes, and snippets.

@jkodroff
Created April 14, 2015 23:52
Show Gist options
  • Save jkodroff/9d49e590b20fe1bb06b2 to your computer and use it in GitHub Desktop.
Save jkodroff/9d49e590b20fe1bb06b2 to your computer and use it in GitHub Desktop.
Working cron expression in Hangfire
var scheduledTime = DateTime.Today.AddHours(19).AddMinutes(-1).ToUniversalTime();
new RecurringJobManager()
.AddOrUpdate(
"upcoming-jobs-email",
Job.FromExpression(() => ObjectFactory.GetInstance<BackgroundJobs.UpcomingJobsEmails>().Run()),
// M-F, 6:59 PM, but in UTC (as Hangfire can only process UTC) and a minute early so it's on the same day
"{0} {1} * * 1-5"
.ToFormat(scheduledTime.Minute, scheduledTime.Hour)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment