I’m new to Hangfire and am trying to figure out a way to allow the user to customize the time to trigger a job. I have a Jquery method to receive input from the user and getting the value. I’m using MVC so the controller is using the basic recurring jobs every minute.
[HttpPost]
public string GetUrlSource(string url){
JobStorage.Current = new SqlServerStorage(ConnectionString);
RecurringJob.AddOrUpdate(()
=> GetUrlSource(url), Cron.Minutely//Trying to change to custom input. There is an input on the view with an id of freqInput and I'm using AJAX call to pull the jquery to the controller and set to a parameter.);
RecurringJob.Trigger("1");
Mathew, I hope I understand your question correctly.
Hangfire can schedule jobs based of cron expressions. With that being said, I would suggest you add a select/drop down on your UI with the cron possibilities listed. Passing the value of the selected item to the controller / hangfire job. See code examples below:
HTML:
<select>
<option value="0 10 * * * ">Every day at 10</option>
<option value="0 10 * * 6">Every Saturday at 10</option>
<option value="0 10 * * 1">Every Monday at 10</option>
</select>
Hangfire:
string cronExp = "0 10 * * *";
RecurringJob.AddOrUpdate(() => Console.WriteLine("Recurring!"), cronExp);