whenever
whenever copied to clipboard
Whenever gem (cron job) not executing rake task, Rails 4
I am trying to run rake task using whenever gem, did everything what was required but fro some reason cant execute the task successfully.
schedule.rb
set :environment, "development"
set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
every 1.minute do
rake "notify:user"
end
notify_user.rake
namespace :notify do
desc "Rake task to push divisions"
task :user => :environment do
t = Division.trigger_divisions
puts "#{Time.now} - Success!" + t.to_s
end
end
I did whenever --update-crontab and also crontab -l
# Begin Whenever generated tasks for: /home/usman/projects/Saloon/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/usman/projects/Saloon && RAILS_ENV=development bundle exec rake notify:user --silent >> log/cron_log.log 2>> log/cron_error_log.log'
# End Whenever generated tasks for: /home/usman/projects/Saloon/config/schedule.rb
# Begin Whenever generated tasks for: store
# End Whenever generated tasks for: store
Log are showing grep CRON /var/log/syslog
Oct 9 15:56:01 usman-Inspiron-3521 CRON[4430]: (usman) CMD (/bin/bash -l -c 'cd /home/usman/projects/Saloon && RAILS_ENV=development bundle exec rake notify:user --silent >> log/cron_log.log 2>> log/cron_error_log.log')
Oct 9 15:57:01 usman-Inspiron-3521 CRON[4453]: (usman) CMD (/bin/bash -l -c 'cd /home/usman/projects/Saloon && RAILS_ENV=development bundle exec rake notify:user --silent >> log/cron_log.log 2>> log/cron_error_log.log')
Oct 9 15:58:01 usman-Inspiron-3521 CRON[4461]: (usman) CMD (/bin/bash -l -c 'cd /home/usman/projects/Saloon && RAILS_ENV=development bundle exec rake notify:user --silent >> log/cron_log.log 2>> log/cron_error_log.log')
Not sure what i am doing wrong here. If i run
cd /home/usman/projects/Saloon && RAILS_ENV=development bundle exec rake notify:user
task executes successfully.
Also, i am using ubuntu 14.04
You havn't included any description of what you believe to be wrong. Is there no output in your specified log files?
Hi Ben, Thanks for the reply. Anything i am trying to execute is not getting executed form the logs i can see that ( logs mentioned above) it is trying to execute but getting failed. Not sure what the reason is. From the example above (rake task) output should be the GCM push trigger (which works if i run the command manually)
Hi Ben, sorry for disturbing you. Is there is any chance you can help. Thanks.
@UsmanMalik Are the log files present? Have you been able to figure out the solution?
Hi, I'm having the same problem I think: created a simple rake task, and added in the schedule.rb set :output, "/log/cron_log.log"
and every 5.minutes do rake "rake:rask" end
... However nothing happens :/
I checked executing directly the cron generated task, which works perfectly. Without any log, I can't understand why we are having this problem. Btw, I'm using Ubuntu 16.04.
Thx in advance for any help!
PS: After completing my schedule.rb I ran whenever --update-crontab myappname --set environment=development
... If it does matter.
Try this: crontab -l | sed 's|bundle|bin/bundle|g' | crontab -
Same proble occured to me. I am using whenever (0.9.7)
I think option 1.minute is not working properly.
every 1.minute do
rake "application:capture_price"
end
this generate
* * * * * /bin/bash -l -c 'cd /directory && RAILS_ENV=development bundle exec rake application:capture_price --silent >> log/cron_log.log 2>> log/cron_error_log.log'
No numbers are generated in this case. only five asterisks.
wheareas
every 2.minutes do
rake "application:capture_price"
end
generates
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /directory && RAILS_ENV=development bundle exec rake application:capture_price --silent >> log/cron_log.log 2>> log/cron_error_log.log'
I think option 1.minute is not working properly.
Cronjobs have a granularity of 1 minute, so five asterisks means "run every minute." The output is correct in this case.
The output for 2 minutes is correct, though definitely too verbose. It could simply be written as
*/2 * * * * /bin/bash -l -c 'cd /directory && RAILS_ENV=development bundle exec rake application:capture_price --silent >> log/cron_log.log 2>> log/cron_error_log.log'
Having the same problem.
Hi all, I was having the same issue, and found out that the system wasn't finding the "bundle" command. The solution was to add
set :output, "log/cron_log.log"
env :PATH, ENV['PATH']
to config/schedule.rb
The first line lets you debug any further whenever/cron issues by adding a log file to your production app. The second line ensures that the bundle command is available.
@nicolasconnault thanks for the solutions. Works like a charm!
What worked for me here was adding
set :job_template, nil
to config/schedule.rb This might lead to different issues though since the readme states that running the command through bash is needed for RVM to work, so YMMV.
@nicolasconnault thank u so much!!! works fine :)
I believe we can close this issue given that it has had no interaction in years and might be stale by now.
cc @benlangfeld