I want to check if/then statement after the delay

27 views
Skip to first unread message

Rachel P

unread,
Jan 30, 2018, 5:08:11 PM1/30/18
to delayed_job
I only want to send a reminder email to an applicant if their application is still in draft 30 days from when they start it. I can't find in the documentation a clear answer for this - does the delay on the job mean the entire method is delayed for 30 days, or the execution of it (the sending) is delayed? What I'd like to do is something like this (maybe not perfect code but you get the idea): 

class EmailReminder
 
def initialize(application)
     
@application = application
 
end
 
def deliver
     
if @application.submitted_date.nil?
         
RemindApplicantMailer.deliver_now
     
end
 
end
  handle_asynchronously
:deliver, :run_at => Proc.new { 30.days.from_now }
end

# applications controller
def create
 
# create @application
  reminder
= EmailReminder.new(@application)
  reminder
.deliver
end

But I can't quite figure out if this would check the submitted date at the time it's called and then delay mail delivery, or if it would successfully wait 30 days before running the method and only deliver if conditions are met. Possibly better to use cron instead.. Thanks for any insight.

-Rachel

David Genord II

unread,
Jan 30, 2018, 5:15:42 PM1/30/18
to delay...@googlegroups.com
In 30 days, DJ will run the deliver method. However this is generally not advised. What if you change the deliver method between now and 30 days from now? What if you change what initializing the class needs between now and then. What if you want to change the reminder timeframe? For this sort of thing, you are better off running a daily cron job that checks for any incomplete applications and sends them a reminder. Possibly store a remind_at or last_reminded timestamp that you can keep pushing out. DJ will do what you are asking for here, it generally isn't a good idea though.

David Genord II

--

---
You received this message because you are subscribed to the Google Groups "delayed_job" group.
To unsubscribe from this group and stop receiving emails from it, send an email to delayed_job+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Mathews

unread,
Jan 30, 2018, 5:33:10 PM1/30/18
to delay...@googlegroups.com
"
 if it would successfully wait 30 days before running the method and only deliver if conditions are met."
^^^ it will do that one.

Rachel P

unread,
Feb 1, 2018, 8:48:05 AM2/1/18
to delayed_job
Thank you! This was helpful.
To unsubscribe from this group and stop receiving emails from it, send an email to delayed_job...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages