Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Further improve offline / retry #574

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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