fix: local server start error should not change to started state (#2052)

This commit is contained in:
Louis 2024-02-16 14:58:34 +07:00 committed by GitHub
parent 7fb61bf0fb
commit 6590ee7a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,6 @@ export const getSystemResourceInfo = async (): Promise<SystemResourceInfo> => {
const cpu = await physicalCpuCount() const cpu = await physicalCpuCount()
const message = `[NITRO]::CPU informations - ${cpu}` const message = `[NITRO]::CPU informations - ${cpu}`
log(message) log(message)
logServer(message)
return { return {
numCpuPhysicalCore: cpu, numCpuPhysicalCore: cpu,

View File

@ -45,7 +45,7 @@ export interface ServerConfig {
* Function to start the server * Function to start the server
* @param configs - Server configurations * @param configs - Server configurations
*/ */
export const startServer = async (configs?: ServerConfig) => { export const startServer = async (configs?: ServerConfig): Promise<boolean> => {
// Update server settings // Update server settings
isVerbose = configs?.isVerboseEnabled ?? true isVerbose = configs?.isVerboseEnabled ?? true
hostSetting = configs?.host ?? JAN_API_HOST hostSetting = configs?.host ?? JAN_API_HOST
@ -123,10 +123,12 @@ export const startServer = async (configs?: ServerConfig) => {
`Debug: JAN API listening at: http://${hostSetting}:${portSetting}` `Debug: JAN API listening at: http://${hostSetting}:${portSetting}`
) )
}) })
return true
} catch (e) { } catch (e) {
// Log any errors // Log any errors
if (isVerbose) logServer(`Error: ${e}`) if (isVerbose) logServer(`Error: ${e}`)
} }
return false
} }
/** /**

View File

@ -122,20 +122,20 @@ const LocalServerScreen = () => {
block block
themes={serverEnabled ? 'danger' : 'primary'} themes={serverEnabled ? 'danger' : 'primary'}
disabled={stateModel.loading || errorRangePort || !selectedModel} disabled={stateModel.loading || errorRangePort || !selectedModel}
onClick={() => { onClick={async () => {
if (serverEnabled) { if (serverEnabled) {
window.core?.api?.stopServer() window.core?.api?.stopServer()
setServerEnabled(false) setServerEnabled(false)
setLoadModelError(undefined) setLoadModelError(undefined)
} else { } else {
startModel(String(selectedModel?.id)) startModel(String(selectedModel?.id))
window.core?.api?.startServer({ const isStarted = await window.core?.api?.startServer({
host, host,
port, port,
isCorsEnabled, isCorsEnabled,
isVerboseEnabled, isVerboseEnabled,
}) })
setServerEnabled(true) if (isStarted) setServerEnabled(true)
if (firstTimeVisitAPIServer) { if (firstTimeVisitAPIServer) {
localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'false') localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'false')
setFirstTimeVisitAPIServer(false) setFirstTimeVisitAPIServer(false)