Put blocking score submission call into a thread to keep the puma server responsive

This commit is contained in:
Ralf Teusner
2016-10-12 18:15:16 +02:00
parent accf0550d7
commit ac88956d27

View File

@ -232,8 +232,13 @@ class SubmissionsController < ApplicationController
hijack do |tubesock| hijack do |tubesock|
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive? Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
# tubesock is the socket to the client # tubesock is the socket to the client
# the score_submission call will end up calling docker exec, which is blocking.
# to ensure responsiveness, we therefore open a thread here.
Thread.new {
tubesock.send_data JSON.dump(score_submission(@submission)) tubesock.send_data JSON.dump(score_submission(@submission))
tubesock.send_data JSON.dump({'cmd' => 'exit'}) tubesock.send_data JSON.dump({'cmd' => 'exit'})
}
end end
end end