Class: StartDebugSessionInteractor
- Inherits:
-
Object
- Object
- StartDebugSessionInteractor
- Includes:
- ADB, Log
- Defined in:
- lib/stf/interactor/start_debug_session_interactor.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(stf) ⇒ StartDebugSessionInteractor
constructor
A new instance of StartDebugSessionInteractor.
Methods included from Log
Constructor Details
#initialize(stf) ⇒ StartDebugSessionInteractor
Returns a new instance of StartDebugSessionInteractor.
13 14 15 |
# File 'lib/stf/interactor/start_debug_session_interactor.rb', line 13 def initialize(stf) @stf = stf end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/stf/interactor/start_debug_session_interactor.rb', line 17 def execute randomized_device = nil 1..10.times do begin devices = @stf.get_devices if devices.nil? || (devices.is_a?(Array) && devices.empty?) logger.info 'No devices connected to STF. Retrying' sleep 5 next end usable_devices = devices.select { |device| device.using == false } if usable_devices.empty? logger.error 'All devices are being used. Retrying' sleep 5 next end randomized_device = usable_devices.sample raise new DeviceNotAvailableError if randomized_device.nil? serial = randomized_device.serial success = @stf.add_device serial if success logger.info "Device #{serial} added" elsif logger.error "Can't add device #{serial}. Retrying" next end result = @stf.start_debug serial if !result.success logger.error "Can't start debugging session for device #{serial}. Retrying" @stf.remove_device serial next end execute_adb_with 30, "connect #{result.remoteConnectUrl}" return Session.new(serial, result.remoteConnectUrl) break raise new DeviceNotAvailableError rescue DeviceNotAvailableError logger.error 'Failed to start debug session. Retrying...' next end end end |