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 | |
| parent | e5bbe3bc4d59b6f35db1ce1b94be14244c11c766 (diff) | |
| download | sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.tar.gz sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.tar.bz2 sncontinue-aa98080cb16c75d2b7d6d9771b97e63120052c62.zip | |
fix: :rocket: fallback s3 bucket
| -rw-r--r-- | .github/workflows/main.yaml | 13 | ||||
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 94 | ||||
| -rw-r--r-- | extension/src/extension.ts | 2 | 
3 files changed, 86 insertions, 23 deletions
| diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index a1d4ff10..8c348024 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -249,7 +249,7 @@ jobs:            aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}            aws-region: us-west-1 -      - name: Upload binaries to S3 +      - name: Upload binaries to S3 (continue-server-binaries)          uses: jakejarvis/s3-sync-action@master          with:            args: --acl public-read --follow-symlinks @@ -259,3 +259,14 @@ jobs:            AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}            AWS_REGION: "us-west-1"            SOURCE_DIR: "exe" + +      - name: Upload binaries to S3 (s3.continue.dev) +        uses: jakejarvis/s3-sync-action@master +        with: +          args: --acl public-read --follow-symlinks +        env: +          AWS_S3_BUCKET: s3.continue.dev +          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} +          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +          AWS_REGION: "us-west-1" +          SOURCE_DIR: "exe" 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);      }    } diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 20af2be6..0b6faa5c 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -7,7 +7,7 @@ import { getExtensionVersion } from "./activation/environmentSetup";  import { getUniqueId } from "./util/vscode";  let client: any = undefined; -async function capture(args: any) { +export async function capture(args: any) {    console.log("Capturing posthog event: ", args);    if (!client) {      const { PostHog } = await import("posthog-node"); | 
