Note that there are some explanatory texts on larger screens.

plurals
  1. PORails3 Whenever not working from cron, but perfectly from terminal
    primarykey
    data
    text
    <p>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.</p> <p>The code to be executed:</p> <pre><code>class SomeModel &lt; ActiveRecord::Base #Delete all items that haven't been updated for 2 hours or more def self.cron_job SomeModel.destroy_all(updated_at &lt; ?", 2.hours.ago]) end end </code></pre> <p>The schedule.rb:</p> <pre><code>set :output, "/var/log/cron" every 1.day, :at =&gt; '4:45 am' do runner "SomeModel.cron_job" end </code></pre> <p>Which generated the following cron (output crontab -l):</p> <pre><code># Begin Whenever generated tasks for: site_name 45 4 * * * /bin/bash -l -c 'cd /home/user/domains/site_name &amp;&amp; script/rails runner -e production '\''SomeModel.cron_job'\'' &gt;&gt; /var/log/cron 2&gt;&amp;1' # End Whenever generated tasks for: site_name </code></pre> <p>If I check the following morning I find this in the cron log:</p> <pre><code>Apr 14 04:45:01 node1 crond[9155]: (root) CMD (/bin/bash -l -c 'cd /home/user/domains/site_name &amp;&amp; script/rails runner -e production '\''SomeModel.cron_job'\'' &gt;&gt; /var/log/cron 2&gt;&amp;1') </code></pre> <p>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>&amp;1' and execute it from the terminal then the items are removed as expected.</p> <p>Also when I execute the code manually from the terminal there are no errors, in the cron log i see the following:</p> <pre><code>from script/rails:5:in 'require' from script/rails:5 from script/rails:5:in 'require' from script/rails:5 </code></pre> <p>At moments where several cron jobs are executed this "error(?)" is printed only once in the log.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload