【问题标题】:Can't get Ruby Whenever working工作时无法获得 Ruby
【发布时间】:2018-05-25 20:14:28
【问题描述】:

我在让whenever 在我的本地开发环境中工作时遇到了一些麻烦。我正在使用mac OS 10.12ruby 2.4rails 5.1whenever 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 的任何活动

不太确定我做错了什么......

【问题讨论】:

  • Test.new.run 是做什么的?难不成它没什么可告诉你的?
  • 它发送一封电子邮件并将记录保存到数据库。我已经在console 中测试过它运行正常。
  • Rails 控制台具有特殊设置,可将数据库查询复制到终端会话以及 ${RAILS_ENV}.log 文件。尝试检查您的应用程序日志中是否有从 cron 作业开始的查询。
  • 我不应该至少看到cron.log文件中的回声吗?
  • 是的,你是对的。你应该。

标签: ruby-on-rails ruby cron whenever


【解决方案1】:

我认为问题可能与rvm 和我设置的.rvmrc 文件有关,当我将cd 放入目录时,该文件加载了正确的rvm 设置。

为了确保命令正常工作,打开一个新的终端窗口并运行:bash -l -c 'cd /Users/me/apps/Test &amp;&amp; bundle exec bin/rails runner -e development '\''Test.new.run'\'' &gt;&gt; /Users/me/apps/Test/log/cron.log 2&gt;&amp;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 文件中仍然没有看到任何内容。

【讨论】:

    猜你喜欢
    • 2011-02-14
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2012-06-14
    • 2023-03-12
    • 2022-07-07
    相关资源
    最近更新 更多