public object GetSettings(string id) { RecurringJobDto job = HangfireJobForm.JobFromId(id); HangfireJobForm result = null; if (job != null) { result = new HangfireJobForm(job); } return(result); }
public object ExecuteNow(HangfireJobForm data) { RecurringJobManager manager = new RecurringJobManager(); RecurringJobDto job = HangfireJobForm.JobFromId(data.Id); manager.Trigger(job.Id); job = HangfireJobForm.JobFromId(data.Id); return(new { data.Id, job.Cron, Success = true, Message = "Hangfire job is now queued for execution.", LastExecuted = HangfireJobForm.GetLocalDateString(job.LastExecution), NextExecution = HangfireJobForm.GetLocalDateString(job.NextExecution) }); }
public object Save(HangfireJobForm data) { RecurringJobManager manager = new RecurringJobManager(); RecurringJobDto job = HangfireJobForm.JobFromId(data.Id); manager.RemoveIfExists(data.Id); manager.AddOrUpdate(data.Id, job.Job, data.Cron, TimeZoneInfo.Local); job = HangfireJobForm.JobFromId(data.Id); while (job.NextExecution == null) { // Wait for the update to be stored in Hangfire's database System.Threading.Thread.Sleep(2000); job = HangfireJobForm.JobFromId(data.Id); } return(new { Success = true, Message = "Settings were saved successfully!", LastExecuted = HangfireJobForm.GetLocalDateString(job.LastExecution), NextExecution = HangfireJobForm.GetLocalDateString(job.NextExecution) }); }