I am learning cron job and delayed job, and I want to send emails using background job; for that I'm using the delayed_job
gem. I don't want to start the worker manually by running the rake jobs:work
command, but I want to set this rake in cron job so whenever an user login into the dashboard this command is fired and a mail is sent to his address. Following is my code:
Sending mail method
def dashboard
@user = User.find(params[:id])
UserMailer.delay.initial_email(@user)
end
UserMailer
def initial_email(user)
@user = user
mail(:to => user.email,:subject => "Welcome to my website!")
end
For the cron job I am using "whenever" Gem, so what should I write in my schedule.rb file so that when I login into the dashboard I get a mail without running worker manually?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…