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

Alter readiness check to use the is_ready API endpoint #278

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/contexts/instance-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export const InstanceProvider = ({ children }) => {
// Clear its timeout when the instance is deleted by user.

const pollingInstance = (app_id, sid, app_url, app_name) => {
// let ready = false;
const decoded_url = decodeURIComponent(app_url);
const executePoll = async () => {
const isAppReady = await api.getAppReady(app_url);
let isAppReady = false;

try {
isAppReady = await api.getAppReady(decoded_url);
} catch(e) {} // just absorb the exception, the default false is correct here
if (isAppReady) {
let newActivity = {
'sid': sid,
Expand Down
24 changes: 11 additions & 13 deletions src/contexts/workspaces-context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,17 @@ export class WorkspacesAPI implements IWorkspacesAPI {
}

@APIRequest()
async getAppReady(appUrl: string, fetchOptions: AxiosRequestConfig={}): Promise<boolean> {
try {
// appUrl is a full URL, not a relative path.
const res = await this.axios.get(appUrl, {
...fetchOptions,
baseURL: undefined
})
return res.status === 200
} catch (e: any) {
return false
}
}
async getAppReady(decodedURL: string, fetchOptions: AxiosRequestConfig={}): Promise<boolean> {
let parts = decodedURL.split('/');
let sid = (parts.length >= 2)?parts[parts.length - 2]:"";

if(sid.length == 0) return false;
const res = await this.axios.get<AppInstanceIsReadyResponse>(`/instances/${ sid }/is_ready/`, {
...fetchOptions
});
if(res.data) return res.data.is_ready;
return false;
}
}

/**
Expand Down Expand Up @@ -416,4 +414,4 @@ export class WorkspacesAPI implements IWorkspacesAPI {
};
return descriptor;
};
}
}
7 changes: 6 additions & 1 deletion src/contexts/workspaces-context/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,18 @@ export interface AppInstance {
cpus: number
gpus: number
memory: string
is_ready: boolean
url: string
status: string
}
export interface AvailableAppsResponse {
[appName: string]: AvailableApp
}
export type AppInstancesResponse = AppInstance[]
export interface AppInstanceIsReadyResponse {
is_ready: boolean
}

export interface UpdateAppInstanceResponse {
status: "success" | "error"
message: string
Expand Down Expand Up @@ -227,4 +232,4 @@ export interface IWorkspacesAPI {
updateAppInstance(sid: string, workspace: string, cpu: string, gpu: string, memory: string, fetchOptions?: AxiosRequestConfig): Promise<UpdateAppInstanceResponse>
launchApp(appId: string, cpus: number, gpus: number, memory: string, fetchOptions?: AxiosRequestConfig): Promise<LaunchAppResponse>
getAppReady(appUrl: string, fetchOptions?: AxiosRequestConfig): Promise<boolean>
}
}
12 changes: 6 additions & 6 deletions src/views/splash-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
if(header !== null) header.style.visibility = "hidden";
if(sidePanel !== null) sidePanel.style.visibility = "hidden";
const { context } = useEnvironment();
const { appstoreContext } = useWorkspacesAPI()
const { api, appstoreContext } = useWorkspacesAPI()
const [loading, setLoading] = useState(true);
const [errorPresent, setErrorPresent] = useState(false);

Expand All @@ -33,14 +33,14 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
(async () => {
try {
await callWithRetry(async () => {
const res = await axios.get(decoded_url)
if (res.status === 200 && shouldCancel === false) {
const isReady = await api.getAppReady(decoded_url);
if (isReady && shouldCancel === false) {
setLoading(false)
} else {
throw new Error("Could not ensure readiness of app URL")
throw new Error("app not ready")
}
}, {
failedCallback: () => {
failedCallback: (e) => {
return shouldCancel
},
timeout: 240000,
Expand Down Expand Up @@ -88,4 +88,4 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
window.location = decoded_url;
}

})
})