Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: update the action of getting screenshot from sync to async to avoid process blocking #466

Merged
merged 4 commits into from
May 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.microsoft.hydralab.common.management.listener.impl.DeviceStabilityMonitor;
import com.microsoft.hydralab.common.management.listener.impl.PreInstallListener;
import com.microsoft.hydralab.common.util.Const;
import com.microsoft.hydralab.common.util.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -51,7 +52,7 @@ public Set<DeviceInfo> getAllConnectedDevice() {
}

public void provideDeviceList(AgentUser.BatteryStrategy batteryStrategy) {
captureAllScreensSync(batteryStrategy);
captureAllScreen(batteryStrategy);
Set<DeviceInfo> allConnectedDevices = getAllConnectedDevice();
ArrayList<DeviceInfo> deviceInfos = new ArrayList<>(allConnectedDevices);
deviceInfos.sort(Comparator.comparing(d -> d.getName() + d.getSerialNum()));
Expand All @@ -63,10 +64,17 @@ public void provideDeviceList(AgentUser.BatteryStrategy batteryStrategy) {
deviceInfos.stream().map(MobileDevice::getSerialNum).collect(Collectors.joining(",")));
}

public void captureAllScreensSync(AgentUser.BatteryStrategy batteryStrategy) {
public void captureAllScreen(AgentUser.BatteryStrategy batteryStrategy) {
Set<DeviceInfo> allConnectedDevices = agentManagementService.getActiveDeviceList(log);
// we need to do this in an async way, otherwise the process will be blocked if one device is not responding
allConnectedDevices.forEach(deviceInfo -> {
deviceDriverManager.getScreenShotWithStrategy(deviceInfo, log, batteryStrategy);
ThreadPoolUtil.SCREENSHOT_EXECUTOR.execute(() -> {
try {
deviceDriverManager.getScreenShotWithStrategy(deviceInfo, log, batteryStrategy);
} catch (Exception e) {
log.error("Failed to capture screenshot for device: {}", deviceInfo.getSerialNum(), e);
}
});
});
}

Expand Down