在西纳特拉运行后台进程 [英] Run background process in Sinatra
问题描述
我有西纳特拉/ Rails应用程序和启动一些长期的过程的操作。
I have got Sinatra/Rails app and an action which starts some long process.
普通我做出后台作业队列。但是,这种情况下,过于简单,后台进程开始很少,所以排队是一个开销。
Ordinary I make a queue for background jobs. But this case is too simple and background process starts very rarely, so queue is an overhead.
所以,我怎么能运行后台进程不排队?
So how could I run background process without queue?
get "/build_logs/:project" do
LogBuilder.new(params[:project]).generate
"done"
end
我试图让它作为一个新的线程或进程叉,但它并没有帮助。
I've tried to make it as a new Thread or Process fork, but it didn't help.
推荐答案
我有这个(简体)在西纳特拉的成功:
I have had success with this (simplified) in Sinatra:
get '/start_process'
@@pid = Process.spawn('external_command_to_run')
end
这将返回进程ID,您可以使用以后终止该进程,如果你需要。此外,这是在Linux上,它不会在Windows上运行。
This returns the Process ID, which you can use to terminate the process later if you need. Also, this is on Linux, it will not work on Windows.
这篇关于在西纳特拉运行后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!