Skip to content

Commit

Permalink
fix: app does not gracefully stop a model
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Apr 3, 2024
1 parent fe89901 commit 4507bb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const stopServer = async () => {
// Log server stop
if (isVerbose) logServer(`Debug: Server stopped`)
// Stop the server
await server.close()
await server?.close()
} catch (e) {
// Log any errors
if (isVerbose) logServer(`Error: ${e}`)
Expand Down
22 changes: 9 additions & 13 deletions web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,13 @@ export function useActiveModel() {
?.loadModel(model)
.then(() => {
setActiveModel(model)
setStateModel(() => ({
state: 'stop',
loading: false,
model: model.id,
}))
toaster({
title: 'Success!',
description: `Model ${model.id} has been started.`,
type: 'success',
})
})
.catch((error) => {
setStateModel(() => ({
state: 'start',
loading: false,
model: model.id,
}))

toaster({
title: 'Failed!',
description: `Model ${model.id} failed to start.`,
Expand All @@ -112,10 +101,17 @@ export function useActiveModel() {
setLoadModelError(error)
return Promise.reject(error)
})
.finally(() => {
setStateModel(() => ({
state: 'start',
loading: false,
model: model.id,
}))
})
}

const stopModel = useCallback(async () => {
if (!activeModel) return
if (!activeModel || stateModel.state === 'stop') return

setStateModel({ state: 'stop', loading: true, model: activeModel.id })
const engine = EngineManager.instance().get(activeModel.engine)
Expand All @@ -126,7 +122,7 @@ export function useActiveModel() {
setActiveModel(undefined)
setStateModel({ state: 'start', loading: false, model: '' })
})
}, [activeModel, setActiveModel, setStateModel])
}, [activeModel, stateModel, setActiveModel, setStateModel])

return { activeModel, startModel, stopModel, stateModel }
}

0 comments on commit 4507bb1

Please sign in to comment.