Skip to content

Commit

Permalink
fix: Further improve offline / retry (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Nov 8, 2024
1 parent ca1a96d commit 626d82d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## UNRELEASED - CLI

- fix: Make `modus --version` just print modus CLI's version [#563](https://github.com/hypermodeinc/modus/pull/563)
- fix: implement retry and caching for CLI downloads [#571](https://github.com/hypermodeinc/modus/pull/571)
- fix: implement retry and caching for CLI downloads [#571](https://github.com/hypermodeinc/modus/pull/571) [#574](https://github.com/hypermodeinc/modus/pull/574)

## UNRELEASED - Runtime

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default class NewCommand extends BaseCommand {
this.logError(`Could not find an installed ${sdkText}.`);
this.exit(1);
} else {
this.logError(`Could not find a locally installed ${sdkText}. Please connect to the internet and try again.`);
this.logError(`Could not find a locally installed ${sdkText}, and you appear to be offline. Please connect to the internet and try again.`);
this.exit(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/util/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import ky from "ky";
// All outbound HTTP requests in the CLI should be made through functions in this file,
// to ensure consistent retry and timeout behavior.

export async function get<T>(url: string, timeout: number | false = 10000) {
export async function get<T>(url: string, timeout: number | false = 5000) {
return await ky.get<T>(url, {
retry: 10, // retry 10 times, up to the default 10s timeout (unless overridden)
retry: 4,
timeout,
});
}
6 changes: 2 additions & 4 deletions cli/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

import chalk from "chalk";
import ora, { Ora } from "ora";

import dns from "node:dns";
import path from "node:path";
import { Readable } from "node:stream";
import { finished } from "node:stream/promises";
import { createWriteStream } from "node:fs";
import * as http from "./http.js";
import * as fs from "./fs.js";
import * as vi from "./versioninfo.js";

export async function withSpinner<T>(text: string, fn: (spinner: Ora) => Promise<T>): Promise<T> {
// NOTE: Ora comes with "oraPromise", but it doesn't clear the original text on completion.
Expand Down Expand Up @@ -60,8 +59,7 @@ export async function isOnline(): Promise<boolean> {
if (online !== undefined) return online;

try {
// we don't need the result here, just checking if the request is successful
await vi.fetchModusLatest();
await dns.promises.lookup("releases.hypermode.com");
online = true;
} catch {
online = false;
Expand Down

0 comments on commit 626d82d

Please sign in to comment.