Using Whenever 0.7.3, Rails 3.2.2, Ruby 1.9.3, Passenger 3.0.11 on a CentOS 5.6 server (I'm not using rvm). The problem is that the cron jobs created by whenever are clearly executed, I can see them in the Cron log, however they don't actually execute the Rails code. If I copy the cron code and paste it in the terminal it works as expected and does.
The code to be executed:
class SomeModel < ActiveRecord::Base
#Delete all items that haven't been updated for 2 hours or more
def self.cron_job
SomeModel.destroy_all(updated_at < ?", 2.hours.ago])
end
end
The schedule.rb:
set :output, "/var/log/cron"
every 1.day, :at => '4:45 am' do
runner "SomeModel.cron_job"
end
Which generated the following cron (output crontab -l):
# Begin Whenever generated tasks for: site_name
45 4 * * * /bin/bash -l -c 'cd /home/user/domains/site_name && script/rails runner -e production '\''SomeModel.cron_job'\'' >> /var/log/cron 2>&1'
# End Whenever generated tasks for: site_name
If I check the following morning I find this in the cron log:
Apr 14 04:45:01 node1 crond[9155]: (root) CMD (/bin/bash -l -c 'cd /home/user/domains/site_name && script/rails runner -e production '\''SomeModel.cron_job'\'' >> /var/log/cron 2>&1')
However the items that should have been deleted are still in the database. If I copy the code cron is supposed to execute (/bin/bash -l -c 'cd ... 2>&1' and execute it from the terminal then the items are removed as expected.
Also when I execute the code manually from the terminal there are no errors, in the cron log i see the following:
from script/rails:5:in 'require'
from script/rails:5
from script/rails:5:in 'require'
from script/rails:5
At moments where several cron jobs are executed this "error(?)" is printed only once in the log.
Is there a difference between executing something from a cronjob or entering the code in the terminal? Why can there be a difference and how do I ensure that it also works from the cronjob? Also is the log output supposed to be an error, it's not telling me much unfortunately.
--
You received this message because you are subscribed to the Google
Groups "Whenever Gem" group and because you're awesome.
To post to this group, send email to whenev...@googlegroups.com
To unsubscribe from this group, send email to
whenever-gem...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/whenever-gem?hl=en