Class: RokuBuilder::DeviceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/roku_builder/device_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(options:, config:) ⇒ DeviceManager

Returns a new instance of DeviceManager.



7
8
9
10
11
# File 'lib/roku_builder/device_manager.rb', line 7

def initialize(options:, config:)
  @config = config
  @options = options
  @timeout_duration = 3600
end

Instance Method Details

#release_device(device) ⇒ Object



37
38
39
40
# File 'lib/roku_builder/device_manager.rb', line 37

def release_device(device)
  lock = lock_file(device)
  File.delete(lock) if File.exist?(lock)
end

#reserve_device(no_lock: false) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/roku_builder/device_manager.rb', line 13

def reserve_device(no_lock: false)
  message = "No Devices Found"
  if @options[:device]
    device = Device.new(@options[:device], @config.raw[:devices][@options[:device].to_sym])
    return device if device_available!(device: device, no_lock: no_lock)
    message = "Device #{@options[:device]} not found"
  else
    begin
      Timeout::timeout(@timeout_duration) do
        loop do
          device = reserve_any(no_lock: no_lock)
          if device
            Logger.instance.info "Using Device: #{device.to_s}"
            return device
          end
          break unless @options[:device_blocking]
        end
      end
    rescue Timeout::Error
    end
  end
  raise DeviceError, message
end