0

I am currently facing some problem to make whenever running as I wish. For example now it is 2:45pm and I want to my task run every 2 hours from now. So it should run at 4:45pm , 6:45pm, 8:45pm, 10:45pm ...

Thank for your help.

Sokmesa Khiev
  • 2,910
  • 3
  • 19
  • 30
  • what's the problem you are facing? – j03w Sep 04 '13 at 08:14
  • I don't know how to write in the schedule.rb to run every 2 hours from the current time. The schedule should start to create a cronjob when I use command whenever to update crontab file. – Sokmesa Khiev Sep 04 '13 at 08:19

1 Answers1

0

Have you tried official docs? Add (or create that file if it doesn't exist) to config/schedule.rb:

every 2.hours do
  #your task here
end

Or use raw cron syntax, somthing like that should be fine:

every '45 */2 * * *' do
  #task
end

This should run job every two hours at xx:45, i.e, 00:45, 2:45, etc.

zrl3dx
  • 7,699
  • 3
  • 25
  • 35
  • Yes but when I use every 2.hours it run at 0,2,4,4,6,8,10 ... not from the current time. Example now is 2:45pm and I want it to run every 45 14,16,18,20,24. So It run from now every two hours. – Sokmesa Khiev Sep 04 '13 at 08:23
  • Ahh, ok, you want to set `minutes` part dynamically? – zrl3dx Sep 04 '13 at 08:27
  • If you want to set it dynamically probably you will have to write sth similar to that: https://github.com/javan/whenever/wiki/Setting-variables-on-the-fly – zrl3dx Sep 04 '13 at 08:30
  • Oh I have one more question. Example now it 7am in the morning. I want my task run every 5 hours. So it will start from 12pm, 5pm, 10pm .. Is there anyways to run the schedule based on the current time? If I put every 5.hours do .. end then it will run at 5am, 10am, 3pm, 8pm ... but I dont want that. I want it run from the current time. – Sokmesa Khiev Sep 04 '13 at 08:46