Not able to test cron job in development using Whenever gem in rails 3

I did the following to implement cron jobs in rails 3 using a “runner” instead of a rake task.

Step 1: I have whenever gem installed and scheduler.rb has following:

  set :environment, 'development'
  set :output, {
 :error => "/log/error.log",
 :standard => "/log/cron.log"
  }

  every 1.minute do
  runner "Cron.sendAutomaticsSMS()"
  end

Step 2:

Cron file: lib/cron.rb

    class Cron < ActiveRecord::Base

      def **sendAutomaticsSMS**()
         ----some code here ---
      end
    end

Step 3:

    whenever --update-crontab --set environment=development

This updates crontab file.

Step 4:

Checked contents of crontab file using:

    crontab -e

It opens cron tab file which has details of cron job method to be invoked:

Any help on this will be greatly appreciated! Thanks.

You’ll want to find where your cron logs to:

And post any errors you find in there.

A first guess is that the environment cron is setting up for your task isn’t the same as the one you use for development; are you using RVM or rbenv? Gemsets?

–Matt Jones

Thanks Matt for your reply! Unfortunately, I don’t see any log file in suggested locations the blog referred to:

/var/log/cron, /var/log/messages and /var/log/syslog

There is no tail trace my development log file generates.

I have not been able to resolve this issue. Tried defining a relative path for log location in scheduler.rb file, but it didn’t help. I don’t see any log file after restarting cron job using: sudo service cron restart and the job as defined in Cron.sendAutomaticsSMS() is not executed.