2

We are using whenever gem on our rails project and there is one task that need to be run every hour but only on the day of the sunday. I understand that i can schedule tasks on hourly basis , by something like this:

every 1.hour do
  # do something
end

and i also understand that i can schedule it for a particular time on sunday:

every :sunday, :at => "11:00pm" do
  #do something
end

what i am looking for is some syntax to schedule this task for every hour on sunday.

Sahil Dhankhar
  • 3,596
  • 2
  • 31
  • 44
  • I have also faced a similar scenario. I created one normal rake task and call it every sunday via cronjob? 00 17 * * 0 cd path_of_your_task RAILS_ENV=production task_name – Arihant Godha Aug 20 '13 at 06:45

1 Answers1

7

You could do something like that

every '0 * * * 7' do
  #...
end

The '0 * * * 7' part is cron syntax:

0 - minutes

first asterisk - every hour

second asterisk - every day

third asterisk - every month

7 - on sundays (7th day of the week)

EDIT - For more detailed information regarding cron tasks syntax, a very clear article can be found here: http://www.thesitewizard.com/general/set-cron-job.shtml

rorofromfrance
  • 1,854
  • 12
  • 21
  • 1
    sounds like a perfect answer, myself did some googling on the basis of the cron syntax example you gave and stumbled upon this http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/ . Those who want to understand this thing in detail can have a look at the examples given in the link. – Sahil Dhankhar Aug 20 '13 at 06:49