Thabo
Thabo

Reputation: 1465

Ruby on Rails crontab task is scheduled but not running

I am using the whenever gem to create the rake task, i am expecting to get a line output "Teaching Thabo how to schedule tasks" on my terminal every 2 minutes, i am new to Rails, here is the code for my rake task file which i have named request_invoice.rake

 namespace :request_invoice do
  desc "Teaching Thabo how to schedule tasks"
  task test_tasking: :environment do
  puts "Learning the tasking in rails..."
  end
 end

And the whenever gem created a schedule.rb file in the config of my project, i have the following code in the file

 every 2.minutes do
 rake 'request_invoice:test_tasking'
 end

I have ran the whenever command on the terminal, it gives the following:

    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,5 2,54,56,58 /bin/bash -l -c 'cd /home/sable/GMS/grading-     management-solution && RAILS_ENV=production bundle exec rake    request_invoice:test_tasking --silent'
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

Upvotes: 0

Views: 2254

Answers (2)

dp7
dp7

Reputation: 6749

First, you need to check whether you have added tasks to crontab or not using:

crontab -e

If you do not see your task, then add it using:

whenever -i

You can track your cron jobs by setting a log file. Just add the following to the top of config/schedule.rb:

set :output, "log/cron_log.log"

Now, you should be able to check your cron logs (if tail is available to you then do the following from the root of your application path):

tail -f log/cron_log.log

Upvotes: 1

Geo
Geo

Reputation: 96767

Did you run the:

whenever --update-crontab

command? According to the gem's page, this is required for your crontab file to be updated.

Upvotes: 1

Related Questions