diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-18 15:41:09 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-18 15:41:09 -0700 |
commit | 53b7fac40d572217c7167075d765ae7dfff56fbe (patch) | |
tree | a3885a6ffae121c5dd68747374be05c2abc1df03 /extension/src/activation | |
parent | 9f4f8d48d51be2d140a722418d0a6c699c0f6cde (diff) | |
download | sncontinue-53b7fac40d572217c7167075d765ae7dfff56fbe.tar.gz sncontinue-53b7fac40d572217c7167075d765ae7dfff56fbe.tar.bz2 sncontinue-53b7fac40d572217c7167075d765ae7dfff56fbe.zip |
a number of things
Diffstat (limited to 'extension/src/activation')
-rw-r--r-- | extension/src/activation/environmentSetup.ts | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index bc071461..593b727e 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -161,6 +161,21 @@ function writeEnvFile(path: string, key: string, value: string) { fs.writeFileSync(path, newEnvFile); } +async function checkServerRunning(serverUrl: string): Promise<boolean> { + // Check if already running by calling /health + try { + const response = await fetch(serverUrl + "/health"); + if (response.status === 200) { + console.log("Continue python server already running"); + return true; + } else { + return false; + } + } catch (e) { + return false; + } +} + export async function startContinuePythonServer() { await setupPythonEnv(); @@ -172,14 +187,7 @@ export async function startContinuePythonServer() { console.log("Starting Continue python server..."); - // Check if already running by calling /health - try { - const response = await fetch(serverUrl + "/health"); - if (response.status === 200) { - console.log("Continue python server already running"); - return; - } - } catch (e) {} + if (await checkServerRunning(serverUrl)) return; let activateCmd = ". env/bin/activate"; let pythonCmd = "python3"; @@ -193,7 +201,7 @@ export async function startContinuePythonServer() { "scripts" )} && ${activateCmd} && cd .. && ${pythonCmd} -m scripts.run_continue_server`; - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { try { const child = spawn(command, { shell: true, @@ -213,7 +221,12 @@ export async function startContinuePythonServer() { }); } catch (e) { console.log("Failed to start Continue python server", e); - reject(); + // If failed, check if it's because the server is already running (might have happened just after we checked above) + if (await checkServerRunning(serverUrl)) { + resolve(null); + } else { + reject(); + } } }); } |