transferred Code Ocean from original repository to GitHub
This commit is contained in:
16
lib/port_pool.rb
Normal file
16
lib/port_pool.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class PortPool
|
||||
PORT_RANGE = DockerClient.config[:ports]
|
||||
|
||||
@available_ports = PORT_RANGE.to_a
|
||||
@mutex = Mutex.new
|
||||
|
||||
def self.available_port
|
||||
@mutex.synchronize do
|
||||
@available_ports.delete(@available_ports.sample)
|
||||
end
|
||||
end
|
||||
|
||||
def self.release(port)
|
||||
@available_ports << port if PORT_RANGE.include?(port) && !@available_ports.include?(port)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user