[英]invoking a script with fork using 'RAILS_ENV=#{Rails.env} bundle exec . . ' doesn't execute (Rails 2.1)
相當神秘的問題,但出於我自己的興趣,我很好奇這是如何起作用的。
我有一個在Rails 2.1的舊系統上運行的cron觸發的腳本
它獲取要執行的任務列表。 由於每個任務可能會長時間運行,因此會使用“ fork”將任務作為后台。
我獲取子進程的pid。 使用“ RAILS_ENV = Rails.env bundle exec child_script”調用該過程不起作用。 刪除RAILS_ENV確實可以工作(注意:直接從命令行運行子腳本就可以了。)
job_script_path = /path/to/child_script.rb
cmd = "RAILS_ENV=#{Rails.env} bundle exec #{job_script_path}
puts "Preparing to run #{cmd}"
ppid = fork{ system(cmd) }
puts "Fetched #{ppid} as parent process"
cpmd = "ps --ppid #{ppid}"
f = IO.popen(cpmd).readlines
puts "Output of #{cpmd}:"
puts "#{f}"
始終輸出:
Preparing to run RAILS_ENV=development bundle exec /path/to/child_script.rb
Fetched 1234 as parent process
Output of ps --ppid 1234
PID TTY TIME CMD
沒有列出進程。
如果我放下RAILS_ENV =#{Rails.env},它就可以正常工作。 設置Rails環境強制原子性怎么樣?
更新:這更多是一個Ruby問題。 我在跑 。 。 。 。 紅寶石1.8.7
顯然,您不能派生在Rails環境中運行的並發進程。 但是,您可以派生不依賴Rails環境的並發進程。
#Do not prepend RAILS_ENV to this, it doesn't allow concurrency (for some reason.)
cmd = "bundle exec #{job.script_path}"
logger.info "Preparing to run #{cmd}"
ppid = fork{ system(cmd) }
logger.info "Fetched #{ppid} as parent process"
剝離Rails的環境。 我沒有找到確定為什么的確切資源。 Rails環境是單塊的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.