def run(self): reboot = self.args.reboot and \ (self.force_reboot or self.device["reboot_time"] + REBOOT_INTERVAL < datetime.datetime.now()) assert self.device["available"] is False, \ "The device to cool down should not be available" success = True if reboot: raw_args = [] raw_args.extend(["--platform", self.args.platform]) raw_args.extend(["--device", self.device["hash"]]) raw_args.extend(["--android_dir", self.args.android_dir]) reboot_device(raw_args=raw_args) time.sleep(120) self.device["reboot_time"] = datetime.datetime.now() if self.args.reboot: # for ios/android time.sleep(180) else: time.sleep(20) with LOCK: getLogger().debug("CoolDownDevice lock acquired") if success: self.device["available"] = True else: self.device["live"] = False device_str = getDevicesString([self.device]) self.db.updateDevices(self.args.claimer_id, device_str, False) getLogger().debug("CoolDownDevice lock released") getLogger().info("Device {}({}) available".format( self.device["kind"], self.device["hash"]))
def run(self): reboot = self.args.reboot and \ (self.force_reboot or self.device["reboot_time"] + REBOOT_INTERVAL < datetime.datetime.now()) success = True # reboot mobile devices if required if reboot: raw_args = [] raw_args.extend(["--platform", self.args.platform]) raw_args.extend(["--device", self.device["hash"]]) raw_args.extend(["--android_dir", self.args.android_dir]) self.device["rebooting"] = True if reboot_device(raw_args=raw_args): getLogger().info("Device {} was rebooted.".format(self.device)) self.device["reboot_time"] = datetime.datetime.now() else: self.device.pop("rebooting") getLogger().error("Device {} could not be rebooted.".format( self.device)) success = False # sleep for device cooldown if self.args.platform.startswith( "ios") or self.args.platform.startswith("android"): getLogger().info("Sleep 180 seconds") time.sleep(180) else: getLogger().info("Sleep 20 seconds") time.sleep(20) with self.LOCK: getLogger().info("CoolDownDevice lock acquired") # device should be available again, remove rebooting flag. if "rebooting" in self.device: del (self.device["rebooting"]) if success: self.device["available"] = True device_str = getDevicesString([self.device]) self.db.updateDevices(self.args.claimer_id, device_str, False) getLogger().info("Device {}({}) available".format( self.device["kind"], self.device["hash"])) else: self.device["live"] = False getLogger().info("CoolDownDevice lock released")