Class: Indocker::BuildContextPool

Inherits:
Object
  • Object
show all
Defined in:
lib/indocker/build_context_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration:, logger:) ⇒ BuildContextPool

Returns a new instance of BuildContextPool.



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/indocker/build_context_pool.rb', line 2

def initialize(configuration:, logger:)
  @logger = logger
  @configuration = configuration

  @contexts = configuration.build_servers.map do |build_server|
    Indocker::BuildContext.new(
      logger: @logger,
      configuration: configuration,
      build_server: build_server,
    )
  end
end

Instance Method Details

#close_sessionsObject



31
32
33
34
35
# File 'lib/indocker/build_context_pool.rb', line 31

def close_sessions
  @contexts.each(&:close_session)
rescue => e
  @logger.error("error during session close: #{e.inspect}")
end

#each(&proc) ⇒ Object



27
28
29
# File 'lib/indocker/build_context_pool.rb', line 27

def each(&proc)
  @contexts.each(&proc)
end

#getObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/indocker/build_context_pool.rb', line 15

def get
  context = nil

  loop do
    context = @contexts.detect {|c| !c.busy?}
    sleep(0.1)
    break if context
  end

  context
end