Search code examples
rufus-scheduler

Rufus Scheduler: How to specify "on the first day of the month, at 8:00am"?


I am trying to configure a schedule that uses the rufus-scheduler gem. I want to create a "once per month" schedule that runs at a specific time. I am trying to use the every syntax for defining it. How can I write this configuration so that it runs every month, on the first day, at 8:00am?


Solution

  • If you read the documentation you link to, you'll notice that rufus-scheduler also has a cron method, here is how you would use it:

    require 'rufus-scheduler'
    
    s = Rufus::Scheduler.new
    
    s.cron '0 8 1 * *' do
      puts "Hello, it's 8 am on the first day of the month"
    end
    

    To answer more squarely, rufus-scheduler "every" syntax doesn't let you specify something like "8am every first day of the month".