public ActionResult ScheduleRecurringJob(NewRecurringJobBE recurringJobConfig) { string recurringJobId = recurringJobConfig.JobId.ToLower();; // 1st remove the Job if it exists RecurringJob.RemoveIfExists(recurringJobId); TimeZoneInfo timeZoneInfo = TimeZoneInfo.Local; switch (recurringJobConfig.ScheduleTimeZone.ToUpper()) { case "EST": timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); break; default: timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); break; } // run the background job immediately //_backgroundJobClient.Enqueue(() => Console.WriteLine("Hello Hangfire job!")); // setup a recurring job #region Using Expression //var manager = new RecurringJobManager(); //manager.AddOrUpdate(recurringJobId, Job.FromExpression(() => Console.WriteLine("Hello Hangfire job!")), @"0-59 * * * MON,TUE,WED,THU,FRI", timeZoneInfo); #endregion #region Using Reflection //RecurringJob.AddOrUpdate(recurringJobId, () => RequestController.EnqueueRequest(@"EventTypeA", // @"FIS.Paymetric.POC.EventTypeA.Plugin.EventTypeAPublisher", // @"FIS.Paymetric.POC.EventTypeA.Plugin", // @"Execute", // @"xtobr"), // @"0-59 * * * MON,TUE,WED,THU,FRI", // timeZoneInfo); #endregion //RecurringJob.AddOrUpdate(recurringJobId, () => RequestController.EnqueueRequest(@"EventTypeA"), // @"0-59 * * * MON,TUE,WED,THU,FRI", // timeZoneInfo); RecurringJob.AddOrUpdate(recurringJobId, () => RequestController.EnqueueRequest(recurringJobConfig.JobId, recurringJobConfig.JobPlugInType), recurringJobConfig.CronSchedule, timeZoneInfo); return(Ok($"Recurring job: [{recurringJobId}] created.")); }