我从浏览器启动长时间运行的进程,并在完成后显示结果。我已经在我的控制器定义:轨道上的红宝石,叉子,长时间运行的后台进程
def runthejob
pid = Process.fork
if pid.nil? then
#Child
output = execute_one_hour_job()
update_output_in_database(output)
# Exit here as this child process shouldn't continue anymore
exit
else
#Parent
Process.detach(pid)
#send response - job started...
end
在父母的要求正确完成。但是,在小孩中,总是会有“500内部服务器错误”。导轨报告“227192ms中完成500内部服务器错误”。我猜这是因为子进程的请求响应周期没有完成,因为有一个“退出”的孩子。我该如何解决?
这是执行长时间运行的进程的正确方法吗?有没有更好的方法来做到这一点?
当孩子运行时,如果我做“
ps -e | grep rails
”,我看到有两个“rails server”实例。 (我用命令“rails server
”开始我的导轨的服务器。)ps -e | grep rails
75678 ttys002 /Users/xx/ruby-1.9.3-p194/bin/ruby script/rails server
75696 ttys002 /Users/xx/ruby-1.9.3-p194/bin/ruby script/rails server
这是否意味着存在正在运行的两个服务器?请求现在如何处理?不请求去第二台服务器?
感谢您的帮助。
另一个资源:https://www.ruby-toolbox.com/categories/Background_Jobs – jordanpg 2012-08-01 20:59:50
如果第一次在轨后台作业的挖,最好的框架,试图在这个时候似乎是Sidekiq。每个人都说这是最快的,而且看起来很简单。 – 2012-08-01 22:26:31
+1对于Sidekiq ...刚刚从DJ切换 – cpuguy83 2012-08-02 02:30:20