Class: Spinny::Server
- Inherits:
-
Object
- Object
- Spinny::Server
- Defined in:
- lib/spinny/server.rb
Overview
Responsible for forking off new code runs
Constant Summary collapse
- DEFAULT_PORT =
8080
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filepath) ⇒ Server
constructor
A new instance of Server.
- #start! ⇒ Object
- #start_http_listener(queue) ⇒ Object
Constructor Details
#initialize(filepath) ⇒ Server
Returns a new instance of Server.
15 16 17 |
# File 'lib/spinny/server.rb', line 15 def initialize(filepath) @filepath = filepath end |
Class Method Details
.connect(port = DEFAULT_PORT) ⇒ Object
11 12 13 |
# File 'lib/spinny/server.rb', line 11 def self.connect(port = DEFAULT_PORT) Connection.new(port) end |
Instance Method Details
#start! ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spinny/server.rb', line 19 def start! require @filepath queue = Queue.new start_http_listener(queue) loop do fork_code = queue.deq pid = fork { eval fork_code } Process.wait pid end end |
#start_http_listener(queue) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spinny/server.rb', line 30 def start_http_listener(queue) Thread.new do server = WEBrick::HTTPServer.new(:Port => DEFAULT_PORT) server.mount_proc '/enqueue' do |req, res| code = CGI.parse(req.body)['code'].first queue.enq(code) end server.start end end |