【发布时间】: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