我在使用whenever
在我的本地开发环境中工作时遇到了一些麻烦。我正在使用mac OS 10.12
,ruby 2.4
,rails 5.1
和whenever 0.10.0
。
我将schedule.rb
文件设置为:
set :environment, "development"
set :job_template, "TZ=\"America/Los_Angeles\" bash -l -c ':job'"
set :output, Whenever.path + "/log/cron.log"
every 5.minutes do
runner "Test.new.run"
command "/bin/echo 'Is this working?'"
end
crontab -l
输出以下内容:
# Begin Whenever generated tasks for: /Users/me/apps/Test/config/schedule.rb at: 2018-05-25 12:59:14 -0700
0,5,10,15,20,25,30,35,40,45,50,55 * * * * TZ="America/Los_Angeles" bash -l -c 'cd /Users/me/apps/Test && bundle exec bin/rails runner -e development '\''Test.new.run'\'' >> /Users/me/apps/Test/log/cron.log 2>&1'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * TZ="America/Los_Angeles" bash -l -c '/bin/echo '\''Is this working?'\'' >> /Users/me/apps/Test/log/cron.log 2>&1'
# End Whenever generated tasks for: /Users/me/apps/Test/config/schedule.rb at: 2018-05-25 12:59:14 -0700
当我在终端中运行mail
命令时,我收到以下信息:
Message 1:
From me@box.local Fri May 25 13:00:01 2018
X-Original-To: me
Delivered-To: me@box.local
From: me@box.local (Cron Daemon)
To: me@box.local
Subject: Cron <me@box> TZ="America/Los_Angeles" bash -l -c '/bin/echo '\''Is this working?'\'' >> /Users/me/apps/Test/log/cron.log 2>&1'
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=me>
X-Cron-Env: <USER=me>
X-Cron-Env: <HOME=/Users/me>
Date: Fri, 25 May 2018 13:00:00 -0700 (PDT)
但是,我没有看到任何输出到cron.log
,数据库也没有反映Test.new.run
的任何活动
不确定我做错了什么......
答案 0 :(得分:1)
我认为问题可能与rvm
和我设置的.rvmrc
文件有关,该文件在rvm
进入目录时加载了正确的cd
设置。
在尝试确保命令正常工作时,打开一个新的终端窗口并运行:bash -l -c 'cd /Users/me/apps/Test && bundle exec bin/rails runner -e development '\''Test.new.run'\'' >> /Users/me/apps/Test/log/cron.log 2>&1'
首先出现的是标准的1关rvm消息:
You are using '.rvmrc', it requires trusting, it is slower and it is not compatible with other ruby managers,
you can switch to '.ruby-version' using 'rvm rvmrc to ruby-version'
or ignore this warning with 'rvm rvmrc warning ignore /Users/me/apps/Test/.rvmrc',
'.rvmrc' will continue to be the default project file in RVM 1 and RVM 2,
to ignore the warning for all files run 'rvm rvmrc warning ignore all.rvmrcs'.
********************************************************************************
* NOTICE *
********************************************************************************
* RVM has encountered a new or modified .rvmrc file in the current directory, *
* this is a shell script and therefore may contain any shell commands. *
* *
* Examine the contents of this file carefully to be sure the contents are *
* safe before trusting it! *
* Do you wish to trust *
* '/Users/me/apps/Test/.rvmrc'? *
* Choose v[iew] below to view the contents *
********************************************************************************
y[es], n[o], v[iew], c[ancel]>
输入y
并按Enter后,cron作业现在正在正常执行。
不幸的是,我仍然没有在cron.log
文件中看到任何内容。