How to create recurring job every 10 minutes for only 24 hours

recurring
Tags: #<Tag:0x00007f78ad1c4df0>

#1

When I have a new customer signup that does not complete the process, I send them an email with next steps. I need to create a job that runs every 10 minutes for the first 24 hours after signup. After that time, there is another process that takes over. I schedule the job like this:

RecurringJob.AddOrUpdate(customerId, () => NewCustomerProcess.checkNewCustomerStatus(customerId)), "*/10 * * * *");

If I add a job start time to the job class:

private DateTime _jobstart = DateTime.UtcNow;

Can I inspect that within the job to figure out when 24 hours has passed then remove the job?

RecurringJob.RemoveIfExists(customerId);

Does hangfire re-instantiate the job class every time it runs?


#2

I don’t think that is going to work out. Every time the recurring job runs it would set _jobstart to the current time.

What I would do is just pass the job start datetime when creating the original recurring job like:
RecurringJob.AddOrUpdate(customerId, () => NewCustomerProcess.checkNewCustomerStatus(customerId, jobStartDateTime)), “*/10 * * * *”);

Then every time the job runs you can check to see if its been 24 hours yet and if so remove the recurring job.