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 1 commit
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
8 changes: 7 additions & 1 deletion src/contexts/workspaces-context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ export class WorkspacesAPI implements IWorkspacesAPI {
await this.axios.delete(`/instances/${ sid }`)
}

@APIRequest()
async getAppInstanceIsReady(sid: string, fetchOptions: AxiosRequestConfig={}): Promise<AppInstanceIsReadyResponse> {
const res = await this.axios.get<AppInstanceIsReadyResponse>(`/instances/${ sid }/is_ready/`);
return res.data;
}

@APIRequest()
async updateAppInstance(
sid: string,
Expand Down Expand Up @@ -416,4 +422,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>
}
}
15 changes: 9 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 @@ -32,15 +32,18 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
let shouldCancel = false;
(async () => {
try {
let parts = decoded_url.split('/');
let sid = (parts.length >= 2)?parts[parts.length - 2]:"";

await callWithRetry(async () => {
const res = await axios.get(decoded_url)
if (res.status === 200 && shouldCancel === false) {
const res = await api.getAppInstanceIsReady(sid);
if (res.is_ready == true && 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 +91,4 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
window.location = decoded_url;
}

})
})
Loading