Rails2.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つのシステム行をプロジェクトスクリプトディレクトリのrubytest.rbファイルに配置し、rubyコマンドを使用して手動で実行する場合は注意してください。
ruby test.rb
これらの2つのシステムコマンドは適切に実行され、インデックスは正しく再構築されます。
私のレーキタスクでは、これら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はまだ実行されていません。
なぜですか?
どうもありがとう。
イヴ