Skip to content

Commit

Permalink
Fix UI (#982)
Browse files Browse the repository at this point in the history
* Fix UI loading devices

* 8.4.7-rc.6
  • Loading branch information
saikrishna321 authored Feb 1, 2024
1 parent ce42199 commit 08ca2e7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-device-farm",
"version": "8.4.7-rc.5",
"version": "8.4.7-rc.6",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/data-service/device-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export async function blockDevice(udid: string, host: string) {
}

export async function unblockDevice(udid: string, host: string) {
unblockDeviceMatchingFilter({ udid, host });
await unblockDeviceMatchingFilter({ udid, host });
}

export async function unblockDeviceMatchingFilter(filter: object) {
Expand Down
28 changes: 13 additions & 15 deletions src/device-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-prototype-builtins */
import {
isMac,
checkIfPathIsAbsolute,
isDeviceFarmRunning,
cachePath,
checkIfPathIsAbsolute,
isAppiumRunningAt,
isDeviceFarmRunning,
isMac,
} from './helpers';
import { ServerCLI } from './types/CLIArgs';
import { Platform } from './types/Platform';
Expand All @@ -16,13 +16,13 @@ import { IDevice } from './interfaces/IDevice';
import { Container } from 'typedi';
import { DeviceFarmManager } from './device-managers';
import {
addNewDevice,
blockDevice,
getAllDevices,
getDevice,
setSimulatorState,
addNewDevice,
removeDevice,
setSimulatorState,
unblockDevice,
blockDevice,
updatedAllocatedDevice,
} from './data-service/device-service';
import log from './logger';
Expand Down Expand Up @@ -199,12 +199,12 @@ export async function initializeStorage() {
Container.set('LocalStorage', localStorage);
}

function getStorage() {
async function getStorage() {
try {
Container.get('LocalStorage');
} catch (err) {
log.error(`Failed to get LocalStorage: Error ${err}`);
initializeStorage();
await initializeStorage();
}
return Container.get('LocalStorage') as LocalStorage;
}
Expand All @@ -217,8 +217,8 @@ function getStorage() {
*/
export async function getUtilizationTime(udid: string) {
try {
const value = await getStorage().getItem(udid);
if (value !== undefined && value && !isNaN(value)) {
const value = (await getStorage()).getItem(udid);
if (value !== undefined && value && !isNaN(await value)) {
return value;
} else {
//log.error(`Custom Exception: Utilizaiton time in cache is corrupted. Value = '${value}'.`);
Expand All @@ -236,7 +236,7 @@ export async function getUtilizationTime(udid: string) {
* @param utilizationTime
*/
export async function setUtilizationTime(udid: string, utilizationTime: number) {
await getStorage().setItem(udid, utilizationTime);
await (await getStorage()).setItem(udid, utilizationTime);
}

/**
Expand Down Expand Up @@ -427,12 +427,10 @@ export async function removeStaleDevices(currentHost: string) {

export async function unblockCandidateDevices() {
const allDevices = await getAllDevices();
const busyDevices = allDevices.filter((device) => {
const isCandidate = device.busy && !device.userBlocked && device.lastCmdExecutedAt != undefined;
return allDevices.filter((device) => {
// log.debug(`Checking if device ${device.udid} from ${device.host} is a candidate to be released: ${isCandidate}`);
return isCandidate;
return device.busy && !device.userBlocked && device.lastCmdExecutedAt != undefined;
});
return busyDevices;
}

export async function releaseBlockedDevices(newCommandTimeout: number) {
Expand Down
12 changes: 2 additions & 10 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,8 @@ class DevicePlugin extends BasePlugin {
}

log.debug(`📱 Update server with Plugin Args: ${JSON.stringify(pluginArgs)}`);

if (pluginArgs.removeDevicesFromDatabaseBeforeRunningThePlugin) {
log.info(
'🔴 Removing all devices from database before running the plugin. You asked for it!',
);
await initializeStorage();
(await ADTDatabase.DeviceModel).removeDataOnly();
}

await initializeStorage();
(await ADTDatabase.DeviceModel).removeDataOnly();
platform = pluginArgs.platform;
androidDeviceType = pluginArgs.androidDeviceType;
iosDeviceType = pluginArgs.iosDeviceType;
Expand Down Expand Up @@ -199,7 +192,6 @@ class DevicePlugin extends BasePlugin {
if (chromeDriverManager) Container.set(ChromeDriverManager, chromeDriverManager);

await addCLIArgs(cliArgs);
await initializeStorage();

log.info(
`📣📣📣 Device Farm Plugin will be served at 🔗 http://${pluginArgs.bindHostOrIp}:${cliArgs.port}/device-farm with id ${DevicePlugin.NODE_ID}`,
Expand Down

0 comments on commit 08ca2e7

Please sign in to comment.