Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Testing Cron Jobs in development environment

I have a custom environment called 'reports' that is setup to hit a slave database. I am trying to configure some cron jobs using the Whenever gem and want to test them in development before I deploy. Is there any way to test cron jobs in development? Is there anyway I could schedule them locally and then start my reports server and see if they run? Thank You!

like image 765
BC00 Avatar asked Oct 22 '22 13:10

BC00


1 Answers

I would start off by reviewing how the gem itself (whenever gem) is conducting their tests. This is an extract from one of their functional test:

context "weekday at a (single) given time" do
    setup do
      @output = Whenever.cron \
      <<-file
        set :job_template, nil
        every "weekday", :at => '5:02am' do
          command "blahblah"
        end
      file
    end

    should "output the command using that time" do
      assert_match '2 5 * * 1-5 blahblah', @output
    end
  end
like image 178
fmendez Avatar answered Oct 24 '22 04:10

fmendez