rufus schedular to run a job at every day at some particular time from the database

631 Views Asked by At

I am working with the rufus schedular to send sms every day, but I want to send the sms every day at 5 pm, I checked in the whenever gem and I can do something like:

every find_day.to_sym, :at => time do
    rake "followup_mail:send_mass_email[#{massemail.id}]"           
end

Time can be like "4:20am". Any suggestions on how to set this up with rufus scheduler.

2

There are 2 best solutions below

3
Vishal On

Try following solution:

scheduler.cron '0 17 * * *' do
  # do something every day, 5pm
end
4
Himanshu Tiwari On

You can try this:-

 recurrence_time = "17:00" #you can make it dynamic.
 scheduled_time = Midnight.parse("every day at #{recurrence_time}")
 scheduler.cron "#{scheduled_time}" do
  # do something every day, recurrence_time
 end

Here you can pass your recurrence from your database. Hope it helps.