1

I'm using the whenever gem for Rails 5. I'm trying to troubleshoot an issue, and after my default schedule.rb file was created at config/schedule.rb, I added some logging directives

# Learn more: http://github.com/javan/whenever
set :environment, "development"

every 10.minutes do
  rake "events:calc_index", :output => {:error => 'error.log', :standard => 'cron.log'}
end

I restarted my Rails server (not sure if that matters or not) but I don't see these log files created anywhere. I have verified my crontab was set up by running "crontab -e" and seeing the job

0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /Users/davea/Documents/workspace/newproj && RAILS_ENV=development bundle exec rake events:calc_index '

Where are the log files created?

Dave
  • 15,639
  • 133
  • 442
  • 830

2 Answers2

0

In your schedule.rb file you can specify the redirection options for your commands at a global or command level by setting the 'output' variable. This example is global level:

  # adds ">> /path/to/file.log 2>&1" to all commands
  set :output, '/path/to/file.log'

and you should put this global level set :output above your job definition, otherwise it wouldn't work Example:

# This works
set :output, {:error => '~/Desktop/z.error.log', :standard => '~/Desktop/z.standard.log'}

every 1.minute do
  command "python ~/Desktop/whe/config/z.py"
end

Taken from: https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

Dori Aviram
  • 292
  • 2
  • 8
  • Yeah but you're hard-coding "~/Desktop/z.error.log" and that directory structure is not present in all my environments. So my question remains, I set the output as you see in my quesiton, so where will those files be generated? – Dave Sep 12 '17 at 20:35
  • You can just use the rails.env to set the path or any configuration instead – Dori Aviram Sep 13 '17 at 18:55
0

According to whenever documentation https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs

you can define output like this with Rails :

set :output, "#{path}/log/cron.log"

So for your exemple you can do :

every 10.minutes do
  rake "events:calc_index", output: {error: "#{path}/log/error.log", standard: "#{path}/log/cron.log"}
end
LiKaZ
  • 306
  • 3
  • 9