In one of my methods i use BackgroundJob.Schedule to schedule a job with and time span of 5 minute.
BackgroundJob.Schedule(() => Console.WriteLine(“Hello, world!”), TimeSpan.FromMinutes(5));
However in those five minute time span if i receive an update,i need to be able to reset the time span to 5 minutes again.
I need to know if its possible to get the instance of a scheduled job and is it possible to reset the time span on the job ?.
i wonder if this is possible?
I am also wondering how this could be done.
Anyone from the Hangfire team looking into this?
Hangfire team, haha (the core team consist of one person yet) I’ve solved this issue by re-creating a job. To do this, you should save the job id somewhere. In my context, I needed to send a notification in time:
class Notification
{
public int Id { get; set; }
public int UserId { get; set; }
public string Text { get; set; }
public string JobId { get; set; }
}
To change the time span, just remove the background job and create a new one:
BackgroundJob.Delete(notification.JobId);
notification.JobId = BackgroundJob.Schedule(/* ... */);
I’ll also think how to simplify this solution in Hangfire itself.
@odinserj, did you ever had a meeting with yourself to discuss how to implement a feature? If so, you’re a team! haha
Thanks for the solution!
Cheers!
Yep, my split personality helps me a lot. One side proposes new features, other side refuses them, and third side makes the decisions
1 Like
Whoo hoo, I pretty much ended up doing the same as odinserj. The only odd thing is that your deleted items basket in dashboard is gonna be clogged: at least in my case it does. As this is not a big issue for me. I didn’t scratch my head over it. Anyways started to use hangfire in our dev environments, seems to be working without a glitch. Planing to move to our prod environment soon.