Forum: Ruby on Rails Not able to test cron job in development using Whenever gem in rails 3

84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-05-28 06:50
(Received via mailing list)
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-ab...
well.
Thanks.
--
Regards,
Ankur
84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-05-29 07:56
(Received via mailing list)
Any help on this will be greatly appreciated! Thanks.

--
Regards,
Ankur
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2014-05-29 18:07
(Received via mailing list)
On Thursday, 29 May 2014 00:55:59 UTC-5, Ankur wrote:
>
>>   }
>>
>>
>>     # Begin Whenever generated tasks for: store
>>
>>
>>
>>
You'll want to find where your cron logs to:

http://unix.stackexchange.com/questions/207/where-...

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
84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-05-30 17:48
(Received via mailing list)
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 am using RVM and bundler for gems. I found similar issue for Rails 4
here
but it is unanswered:

http://stackoverflow.com/questions/23387065/cronta...

I think *whenever* is a heavily used rails gem and other developers on
this
forum who have used this gem can help debugging this problem as well. I
hope I followed all the steps for integration.

Thanks.
--
Regards,
Ankur
84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-06-07 23:58
(Received via mailing list)
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.

*************
*RAILS_ROOT/config/scheduler.rb*

 set :environment, 'development'


log_dir = File.expand_path("../log/", __FILE__)

set :output, {

  :error    => File.join(log_dir, "error.log"),

  :standard => File.join(log_dir, "cron.log")

}

every 1.minute do

  runner "Cron.sendAutomaticsSMS()"

end

*************


Please help me with this.

Thanks.

--
Regards,
Ankur
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.