【问题标题】:run rake ts:index from within a rake task从 rake 任务中运行 rake ts:index
【发布时间】:2012-11-15 13:29:54
【问题描述】:

我正在运行 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 正确调用和执行。

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

ruby test.rb

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

在我的 rake 任务中,我尝试将这 2 个系统行替换为:

%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 仍未执行。

知道为什么吗?

非常感谢。

伊夫

【问题讨论】:

  • 只是为了澄清。我的帖子有错别字。描述和任务名称真的没问题,即两者:test_task 而不是 test_synchro_task。

标签: command rake system task sphinx


【解决方案1】:

问题已解决:

1- 在 ruby​​ 脚本中,我发现 $?.exitstatus 为 127,即“找不到命令”。

2- 这提示我在 cron 上下文中出现 PATH 问题。

3- 发现帖子:http://dewful.com/?p=157,标题为“Ruby - Cron Not Working For Ruby Script”。

4- 在 crontab 中添加了 PATH,一切正常。

伊夫

【讨论】:

    猜你喜欢
    • 2010-10-09
    • 2014-12-05
    • 2019-05-31
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 2013-02-18
    相关资源
    最近更新 更多