So I'm using Hangfire schedule jobs that send out reminders to users. Whenever I set the Job to run every monday for example at 14h00. If I do this in the morning say at 09h00. The first execution, should go off at 14h00. Problem is what seems to be happening is when I look in the dashboard it says Next execution is in 7 days.
Heres the code :
public class ReminderTimeService : IReminderTimeService
{
private readonly IRecurringJobManager _recurringJobClient;
public ReminderTimeService(
IRecurringJobManager recurringJobClient)
{
_recurringJobClient = recurringJobClient;
}
public void ScheduleJobs(List<ReminderTime> reminderTimeList)
{
foreach (var reminder in reminderTimeList)
{
_recurringJobClient.AddOrUpdate<IProactiveMessageService>(
// Job Id
$"send-status-set-reminder-{reminder.Day.Substring(0, 3)}-
{reminder.StartTime.Split(":")[0]}-{reminder.StartTime.Split(":")[1]}",
// Service to run work
c => c.SendStatusSetReminder(),
// Repeat weekly
GetWeekCronExpression(reminder.Day, reminder.StartTime),
// Use local time
TimeZoneInfo.Local);
}
private DayOfWeek GetDayOfTheWeek(string day)
{
switch (day)
{
case "Monday":
return DayOfWeek.Monday;
case "Tuesday":
return DayOfWeek.Tuesday;
case "Wednesday":
return DayOfWeek.Wednesday;
case "Thursday":
return DayOfWeek.Thursday;
case "Friday":
return DayOfWeek.Friday;
default:
return DayOfWeek.Monday;
}
}
private string GetWeekCronExpression(string day, string time)
{
var hour = Convert.ToInt16(time.Split(":")[0]);
var minute = Convert.ToInt16(time.Split(":")[1]);
var weekStartExp = Cron.Weekly(GetDayOfTheWeek(day), hour, minute);
return weekStartExp;
}
}
}
My guess is theres something I'm fundamentally not understanding or theres a bug with Hangfire. In any case I'm happy to just get a work around.
Thanks