2

I would like to use Heroku scheduler to run every OTHER Monday. However, it only runs hourly, daily, every 10 minutes.

I read this... How can I schedule a 'weekly' job on Heroku?

However, I'm not sure what code can be used. I think I can figure out every Monday, but not every OTHER Monday.

thanks

Community
  • 1
  • 1
user2012677
  • 5,465
  • 6
  • 51
  • 113

1 Answers1

3

As you get more complicated, I'd recommend checking out scheduling gems. If you want to stick to vanilla Ruby, look at a combination of monday? and cweek, which tells you the week number in the current year. Run your job on Mondays in even-numbered weeks.

date = Date.today
date.monday? && date.cweek.even?

Note that cweek can return 53, since 365 isn't divisible by 7 and it has to handle that last, partial week. The new year's first week will be 1 (it doesn't count from 0), so you have to either skip a week or do two runs in a row when Monday falls in week 53.

Kristján
  • 18,165
  • 5
  • 50
  • 62