Mini_scheduler execute Job every monday at 4am UTC

I am wondering how to use the mini_scheduler gem to create a Job that will run every Monday at a specific time.

I found the option every 1.week on the Discourse code base but I am not sure when this will be triggered.

AFAIK, there’s no option in mini scheduler to specify the day on which a job runs, but we do have an option to make a job run daily at a specific time. So we can configure our job like so daily at: 4.hours and then in the execute method we only do our logic if the day is Monday.

module Jobs
  class YourCustomJob < ::Jobs::Scheduled
    daily at: 4.hours

    def execute(args)
      return if !Time.zone.now.monday?

      # it has to be Monday at this point
    end
  end
end
4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.