I've written my first rake task in rails, I've set it up with the Heroku scheduler and it is getting run, however the mail isn't getting sent. My mail settings are fine as I'm using it for various other things, I would imagine it's a problem with my code in the rake task. Any help would be much appreciated.
lib/tasks/uncomplete_form.rake
desc "Remind users if they haven't completed quote form"
task uncomplete_form: :environment do
puts 'Reminding users of uncomplete quote form'
date = Date.parse('december 18 2016')
quickcontacts = Quickcontact.where(created_at: date.midnight..Time.now)
quickcontacts.each do |quickcontact|
next unless quickcontact.created_at > 1.hour.ago
if quickcontact.p_p = nil
QuickcontactMailer.uncomplete_form(@quickcontact).deliver
end
end
puts 'done.'
end
By running rake uncomplete_form I get
Reminding users of uncomplete quote form
done.
And running heroku run rake uncomplete_form I get
Reminding users of uncomplete quote form
Quickcontact Load (1.5ms) SELECT "quickcontacts".* FROM "quickcontacts" WHERE ("quickcontacts"."created_at" BETWEEN '2016-12-18 00:00:00.000000' AND '2016-12-20 12:09:23.683977')
done.
It doesn't seem to be picking up any quickcontacts - however if in the console I run:
date = Date.parse('december 18 2016')
followed by
quickcontacts = Quickcontact.where(created_at: date.midnight..Time.now)
It does find the expected contacts
Have you tried
?
Edit: What's .p_p supposed to be? You're doing assignment in that if clause instead of what I presume should have been comparison (?)