1

我正在运行 Rails 2.3.5。

在我的项目中,我在 lib/tasks 中有以下 rake 任务(test_task.rake):

desc 'test_synchro_task'
task :test_synchro_task => :environment do
    # A bunch of things that are properly executed (basically I am inserting 
    # in the database)...
    # ...
    # and once the above is done, I want the following to be executed,
    # the sphinx index to be rebuild, but it is NOT :
    system("cd /sites/project/app")
    system("RAILS_ENV='staging' rake ts:index")
end

我通过包含以下条目的 crontab 触发任务的执行:

13 14 * * * cd /sites/project/app && /sites/ruby/bin/rake RAILS_ENV=staging test_task

除了任务中的 2 个系统行之外,哪个 id 正确调用和执行。

请注意,当我将这两个系统行放在我的项目脚本目录中的 ruby​​ test.rb 文件中时,并使用 ruby​​ 命令手动运行它:

ruby test.rb

这 2 个系统命令已正确执行,并且索引已正确重建。

在我的 rake 任务中,我尝试通过以下方式替换这两个系统行:

%x["cd /sites/project/app"]
%x["RAILS_ENV='staging' rake ts:index"]

或通过

@cmd="cd /sites/project/app; RAILS_ENV='staging' rake ts:index"
`#{@cmd}`

但 rake ts:index 仍未执行。

知道为什么吗?

非常感谢。

伊夫

4

1 回答 1

0

Problem resolved:

1- In the ruby script, I found that the $?.exitstatus was 127, which is "command not found".

2- This hinted me to a PATH problem occurring in the context of cron.

3- Found that post: http://dewful.com/?p=157 titled "Ruby - Cron Not Working For Ruby Script".

4- Added the PATH in the crontab and everything works fine.

Yves

于 2012-12-04T16:17:10.823 回答