得不到 Ruby 每当工作
Can't get Ruby Whenever working
我在让 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
的任何 activity
不太确定我做错了什么...
我认为问题可能与 rvm
和我设置的 .rvmrc
文件有关,当我 cd
进入时加载了正确的 rvm
设置目录。
为了确保命令正常运行,打开了一个新终端 window 和 运行: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 off 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
并按下回车键后,cron 作业现在可以正常执行了。
不幸的是,我的 cron.log
文件中仍然没有看到任何内容。
我在让 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
不太确定我做错了什么...
我认为问题可能与 rvm
和我设置的 .rvmrc
文件有关,当我 cd
进入时加载了正确的 rvm
设置目录。
为了确保命令正常运行,打开了一个新终端 window 和 运行: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 off 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
并按下回车键后,cron 作业现在可以正常执行了。
不幸的是,我的 cron.log
文件中仍然没有看到任何内容。