2017-09-12 152 views
0

我使用的是每當寶石爲Rails 5.我試圖解決的一個問題,我的默認schedule.rb文件在配置/ schedule.rb創建之後,我添加了一些日誌指令我在哪裏可以找到我的日誌文件?

# 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 

我重新啓動了我的Rails服務器(不確定是否重要),但沒有在任何地方看到這些日誌文件。我已經驗證了我的crontab成立了由運行「crontab -e命令」,看到哪裏有日誌文件創建的作業

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 ' 

回答

0

在您的schedule.rb文件中,您可以通過設置'output'變量來在全局或命令級別爲您的命令指定重定向選項。這個例子是全球層面:

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

,你應該把這個全球層面設定:輸出你的工作定義的上方,否則將無法正常工作 例子:

# 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 

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

+0

是的,但你正在編碼「〜/ Desktop/z.error.log」,並且該目錄結構不存在於我的所有環境中。所以我的問題仍然存在,我按照你在我的問題中看到的那樣設置輸出,那麼這些文件將在哪裏生成? – Dave

+0

您可以使用rails.env來設置路徑或任何配置 –

相關問題