diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-09-02 23:00:57 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-09-02 23:00:57 -0700 |
commit | aa98080cb16c75d2b7d6d9771b97e63120052c62 (patch) | |
tree | 810ebb2856cdd2e8dc9b02dcd0953b74a1c3c083 /extension/src/activation | |
parent | e5bbe3bc4d59b6f35db1ce1b94be14244c11c766 (diff) | |
download | sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.tar.gz sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.tar.bz2 sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.zip |
fix: :rocket: fallback s3 bucket
Diffstat (limited to 'extension/src/activation')
-rw-r--r-- | extension/src/activation/environmentSetup.ts | 94 |
1 files changed, 73 insertions, 21 deletions
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 9be495ff..4493a6af 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -1,4 +1,4 @@ -import { getExtensionUri } from "../util/vscode"; +import { getExtensionUri, getUniqueId } from "../util/vscode"; import { promisify } from "util"; import { exec as execCb } from "child_process"; import { spawn } from "child_process"; @@ -11,6 +11,7 @@ import * as os from "os"; import fkill from "fkill"; import { finished } from "stream/promises"; import request = require("request"); +import { capture } from "../extension"; const exec = promisify(execCb); @@ -149,35 +150,41 @@ export async function downloadFromS3( bucket: string, fileName: string, destination: string, - region: string + region: string, + useBackupUrl: boolean = false ) { - try { - ensureDirectoryExistence(destination); - const file = fs.createWriteStream(destination); - const download = request({ - url: `https://${bucket}.s3.${region}.amazonaws.com/${fileName}`, - }); + ensureDirectoryExistence(destination); + const file = fs.createWriteStream(destination); + const download = request({ + url: useBackupUrl + ? `https://s3.continue.dev/${fileName}` + : `https://${bucket}.s3.${region}.amazonaws.com/${fileName}`, + }); + + return new Promise(async (resolve, reject) => { + const handleErr = () => { + if (fs.existsSync(destination)) { + fs.unlink(destination, () => {}); + } + }; download.on("response", (response: any) => { if (response.statusCode !== 200) { - throw new Error("No body returned when downloading from S3 bucket"); + handleErr(); + reject(new Error("No body returned when downloading from S3 bucket")); } }); download.on("error", (err: any) => { - if (fs.existsSync(destination)) { - fs.unlink(destination, () => {}); - } - throw err; + handleErr(); + reject(err); }); download.pipe(file); await finished(download); - } catch (err: any) { - const errText = `Failed to download Continue server from S3: ${err.message}`; - vscode.window.showErrorMessage(errText); - } + resolve(null); + }); } export async function startContinuePythonServer(redownload: boolean = true) { @@ -240,7 +247,7 @@ export async function startContinuePythonServer(redownload: boolean = true) { vscode.window.showErrorMessage( `It looks like the Continue server is taking a while to download. If this persists, you can manually download the binary or run it from source: https://continue.dev/docs/troubleshooting#run-the-server-manually.` ); - }, 20_000); + }, 35_000); let download = vscode.window.withProgress( { @@ -249,15 +256,60 @@ export async function startContinuePythonServer(redownload: boolean = true) { cancellable: false, }, async () => { - await downloadFromS3(bucket, fileName, destination, "us-west-1"); + try { + await downloadFromS3( + bucket, + fileName, + destination, + "us-west-1", + false + ); + } catch (e: any) { + console.log("Failed to download from primary url, trying backup url"); + + capture({ + distinctId: getUniqueId(), + event: "first_binary_download_failed", + properties: { + extensionVersion: getExtensionVersion(), + os: os.platform(), + arch: os.arch(), + error_msg: e.message, + }, + }); + + try { + await downloadFromS3( + bucket, + fileName, + destination, + "us-west-1", + true + ); + } catch (e: any) { + capture({ + distinctId: getUniqueId(), + event: "second_binary_download_failed", + properties: { + extensionVersion: getExtensionVersion(), + os: os.platform(), + arch: os.arch(), + error_msg: e.message, + }, + }); + + throw e; + } + } } ); try { await download; console.log("Downloaded server executable at ", destination); clearTimeout(timeout); - } catch (e) { - console.log("Failed to download server executable", e); + } catch (e: any) { + const errText = `Failed to download Continue server from S3: ${e}`; + vscode.window.showErrorMessage(errText); } } |