Ankur Kumar
2014-May-28  04:48 UTC
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:
------------------------------
    # Begin Whenever generated tasks for: store
    # End Whenever generated tasks for: store
    # Begin Whenever generated tasks for:
/code/rails_projects/new/bhk/bigbhk-     dev/config/schedule.rb
    * * * * * /bin/bash -l -c 'cd <*RAILS_APP_PROJECT_LOCATION*>
&&
script/rails runner -e development
'\''**Cron.sendAutomaticsSMS()**'\'' >$
    # End Whenever generated tasks for: /code/rails_projects/new/bhk/bigbhk-dev/
 *Step 5:*
Running cron job:
    $sudo service cron restart
    cron stop/waiting
    cron start/running, process 4027
 This does not do anything. I wait for operation as defined in
sendAutomaticsSMS() method to execute but the cron doesn't even enter this
method.
I don't see any error in log/development.log and there is no log/cron.log
in my rails app.
Posted this question on
Stackoverflow<http://stackoverflow.com/questions/23880580/not-able-to-test-cron-job-using-whenever-gem-in-rails-3>as
well.
Thanks.
--
Regards,
Ankur
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/CALSL1eOxissu-xbc0KZeQpZ_pX8p6mr9ZVu6aXB%2Bfh4EHhgLrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.