How to test rake tasks with Whenever Gem?

1.4k Views Asked by At

I'm trying to execute a simple rake task using whenever gem but the code isn't being executed.

I already set the environment to development, I updated the cron using the whenever --update-crontab command and the rake task works well if I run the command on console. But, when I run the server the log file is not being generated.

I saw a question here too with the same problem but it was solved setting the environment to development, but didn't work out for me.

My rake task:

namespace :testando do
  task :consulta => :environment do
    produto = Produto.first
    puts produto.nm_produto
  end  
end

My schedule.rb:

set :output, "#{path}/log/cron_log.log"
set :environment, 'development'

every 1.minute do
  rake "testando:consulta"
end

I'm using rails 5.0.0.1 and I'm programing in Cloud9, so I think the OS is Ubuntu.

What's missing ?

Update:

I followed the instructions of the main answer in this topic Cron job not working in Whenever gem

And it worked! The task is running even with the server not being started (with "rails s" command).

1

There are 1 best solutions below

1
On

please run crontab -l to see if you have updated the crontab successfully