Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/contexts/instance-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const InstanceProvider = ({ children }) => {
let isAppReady = false;

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

@APIRequest()
async getAppReady(decodedURL: string, fetchOptions: AxiosRequestConfig={}): Promise<boolean> {
const parts = decodedURL.split('/');
const sid = (parts.length >= 2)?parts[parts.length - 2]:"";

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

@APIRequest()
async getAppReadyByURL(decodedURL: string, fetchOptions: AxiosRequestConfig={}): Promise<boolean> {
const parts = decodedURL.split('/');
const sid = (parts.length >= 2)?parts[parts.length - 2]:"";

if(sid.length == 0) return false;
return await this.getAppReady(sid, fetchOptions)
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/workspaces-context/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@ export interface IWorkspacesAPI {
stopAppInstance(sid: string, fetchOptions?: AxiosRequestConfig): Promise<void>
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>
getAppReady(sid: string, fetchOptions?: AxiosRequestConfig): Promise<boolean>
getAppReadyByURL(decodedURL: string, fetchOptions?: AxiosRequestConfig): Promise<boolean>
}
2 changes: 1 addition & 1 deletion src/views/splash-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SplashScreenView = withWorkspaceAuthentication((props) => {
(async () => {
try {
await callWithRetry(async () => {
const isReady = await api.getAppReady(decoded_url);
const isReady = await api.getAppReadyByURL(decoded_url);
if (isReady && shouldCancel === false) {
setLoading(false)
} else {
Expand Down
38 changes: 28 additions & 10 deletions src/views/workspaces/active.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useEffect, useState } from 'react';
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
import { Button, Col, Form, Input, Layout, Modal, Table, Typography, Slider, Spin, Row, Progress, Space, Tooltip } from 'antd';
import { DeleteOutlined, RightCircleOutlined, LoadingOutlined, CloseOutlined, ExclamationOutlined, QuestionOutlined } from '@ant-design/icons';
import { NavigationTabGroup } from '../../components/workspaces/navigation-tab-group';
Expand All @@ -20,7 +20,6 @@ export const ActiveView = withWorkspaceAuthentication(() => {
const [instances, setInstances] = useState();
const [apps, setApps] = useState();
const [refresh, setRefresh] = useState(false);
const [isLoading, setLoading] = useState(false);
const { api } = useWorkspacesAPI()
const { appSpecs, appActivityCache, getLatestActivity } = useActivity();
const { analyticsEvents } = useAnalytics();
Expand All @@ -44,19 +43,29 @@ export const ActiveView = withWorkspaceAuthentication(() => {

useTitle("Active Workspaces")

const isLoading = useMemo(() => instances === undefined, [instances])

useEffect(() => {
const renderInstance = async () => {
setLoading(true);
let stale = false
// We poll the instances endpoint to periodically update readiness probe values.
// This approach is simpler than individually polling each app's readiness.
const pollInstances = async () => {
try {
const instances = await api.getAppInstances()
if (stale) return
setInstances(instances)
setTimeout(pollInstances, 5000)
} catch (e) {
if (stale) return
setInstances([])
openNotificationWithIcon('error', 'Error', 'An error has occurred while loading instances.')
setTimeout(pollInstances, 2500)
}
setLoading(false);
}
renderInstance();
pollInstances()
return () => {
stale = true
}
}, [refresh, api])

useEffect(() => {
Expand All @@ -70,10 +79,12 @@ export const ActiveView = withWorkspaceAuthentication(() => {
openNotificationWithIcon('error', 'Error', 'An error has occurred while loading app configuration.')
}
}
if (instances && instances.length === 0) setTimeout(() => navigate('/helx/workspaces/available'), 1000)
else loadAppsConfig();
loadAppsConfig();
}, [api])

}, [instances, api])
useEffect(() => {
if (instances && instances.length === 0) setTimeout(() => navigate('/helx/workspaces/available'), 1000)
}, [instances])

const stopInstanceHandler = async () => {
// besides making requests to delete the instance, close its browser tab and stop polling service
Expand Down Expand Up @@ -202,7 +213,14 @@ export const ActiveView = withWorkspaceAuthentication(() => {
let activity = getLatestActivity(record.sid)
let indicator = null
let statusText = null
switch (activity?.data.status) {

let status = activity?.data.status
if (status === "LAUNCHED") {
// Containers may be launched but also need to ensure the pod readiness probe has passed,
// otherwise display as still launching.
if (record.status !== "ready") status = "LAUNCHING"
}
switch (status) {
case "LAUNCHING":
indicator = <Spin indicator={ <LoadingOutlined style={{ fontSize: 16 }} spin /> } />
statusText = "Launching"
Expand Down