Search code examples
ruby-on-railscronresque

cron on resque scheduler not working on preferred intervals


I need to run a task precisely on 10AM every thursday,

on resque yaml file I am trying this

cron: "* 10 * * 4 * America/New_York"  # expecting this to shoot out every thursday..

Was that correct? I can't test it out as I can't wait for such an interval, so I tried to test it at least for every 5 mins but it isn't very promising

cron: "5 * * * * *"  # It runs for every single minute..

any help or direction is appreciated.

I followed this

* * * * * *
| | | | | | 
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)

Solution

  • Regex expressions can have 5 or 6 placeholders. Not every framework/implementation supports both ways so you have to check which format you need.

    Your expression cron: "5 * * * * *" would run every minute exactly 5 seconds past the minute. I think in your case, you could use only 5 placeholders which means that you can not schedule for seconds but only for minutes.

    Also, to run something every 5 minutes, you need the following expression:

    cron: "*/5 * * * *" 
    

    Every 10AM on thursday should be:

    cron: "0 10 * * 4 America/New_York"
    

    Meaning:

    • every thursday (4)
    • every month
    • every day
    • 10 hours
    • 0 minutes

    (I have not tested this.)