detect status
This commit is contained in:
parent
db61d3f7f9
commit
7ba90ae7af
@ -6,9 +6,9 @@ Model_Config = "model_config"
|
||||
|
||||
|
||||
class ModelStatus(Enum):
|
||||
Offline = auto()
|
||||
Loading = auto()
|
||||
Working = auto()
|
||||
Offline = 0
|
||||
Loading = 2
|
||||
Working = 3
|
||||
|
||||
|
||||
def init():
|
||||
|
@ -59,3 +59,8 @@ def update_config(body: ModelConfigBody):
|
||||
global_var.set(global_var.Model_Config, body)
|
||||
|
||||
return "success"
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
def status():
|
||||
return {"status": global_var.get(global_var.Model_Status)}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import commonStore from '../stores/commonStore';
|
||||
import commonStore, {ModelStatus} from '../stores/commonStore';
|
||||
|
||||
export const readRoot = async () => {
|
||||
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
|
||||
@ -35,3 +35,17 @@ export const updateConfig = async (body: any) => {
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
};
|
||||
|
||||
export const getStatus = async (timeout?: number): Promise<ModelStatus | undefined> => {
|
||||
const controller = new AbortController();
|
||||
if (timeout)
|
||||
setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
|
||||
let ret: ModelStatus | undefined;
|
||||
await fetch(`http://127.0.0.1:${port}/status`, {signal: controller.signal}).then(r => r.json()).then(data => {
|
||||
ret = data.status;
|
||||
}).catch(() => {
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
@ -1,11 +1,16 @@
|
||||
import commonStore, {defaultModelConfigs} from './stores/commonStore';
|
||||
import {ReadJson} from '../wailsjs/go/backend_golang/App';
|
||||
import {downloadProgramFiles, LocalConfig, refreshModels} from './utils';
|
||||
import {getStatus} from './apis';
|
||||
|
||||
export async function startup() {
|
||||
downloadProgramFiles();
|
||||
initCache();
|
||||
await initConfig();
|
||||
getStatus(500).then(status => {
|
||||
if (status)
|
||||
commonStore.setModelStatus(status);
|
||||
});
|
||||
}
|
||||
|
||||
async function initConfig() {
|
||||
|
Loading…
Reference in New Issue
Block a user