#665·whenever

Whenever gem (cron job) not executing rake task, Rails 4

Author: UsmanMalikCreated Oct 9, 2016Updated Nov 13, 2023
Labelsawaiting-feedback

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

ruby
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

ruby
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.