fix(core): log background models.dev refresh failures at debug
This commit is contained in:
parent
5455fed78e
commit
9dfc3732ff
2 changed files with 73 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import path from "path"
|
||||
import { Context, Duration, Effect, Layer, Option, Schedule, Schema } from "effect"
|
||||
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http"
|
||||
import { HttpClient, HttpClientRequest } from "effect/unstable/http"
|
||||
import { ModelsDev } from "@opencode-ai/schema/models-dev"
|
||||
import { Global } from "./global"
|
||||
import { Flag } from "./flag/flag"
|
||||
|
|
@ -212,7 +212,7 @@ const layer = Layer.effect(
|
|||
|
||||
const get = (): Effect.Effect<Record<string, Provider>> => cachedGet
|
||||
|
||||
const refresh = Effect.fn("ModelsDev.refresh")(function* (force = false) {
|
||||
const attempt = Effect.fn("ModelsDev.refresh.attempt")(function* (force = false) {
|
||||
if (!force && (yield* fresh())) return
|
||||
yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
|
|
@ -224,7 +224,11 @@ const layer = Layer.effect(
|
|||
yield* invalidate
|
||||
yield* events.publish(Event.Refreshed, {})
|
||||
}),
|
||||
).pipe(
|
||||
)
|
||||
})
|
||||
|
||||
const refresh = Effect.fn("ModelsDev.refresh")(function* (force = false) {
|
||||
yield* attempt(force).pipe(
|
||||
Effect.tapCause((cause) => Effect.logError("Failed to fetch models.dev", { cause: cause })),
|
||||
Effect.ignore,
|
||||
)
|
||||
|
|
@ -232,7 +236,16 @@ const layer = Layer.effect(
|
|||
|
||||
if (!Flag.OPENCODE_DISABLE_MODELS_FETCH && !process.argv.includes("--get-yargs-completions")) {
|
||||
// Schedule.spaced runs the effect once, then waits between completions.
|
||||
yield* Effect.forkScoped(refresh().pipe(Effect.repeat(Schedule.spaced("60 minutes")), Effect.ignore))
|
||||
// Keep best-effort background failures at Debug: before the file logger is
|
||||
// installed, Effect's default logger writes to stdout, which corrupts the TUI.
|
||||
yield* Effect.forkScoped(
|
||||
attempt().pipe(
|
||||
Effect.tapCause((cause) => Effect.logDebug("Failed to fetch models.dev", { cause: cause })),
|
||||
Effect.ignore,
|
||||
Effect.repeat(Schedule.spaced("60 minutes")),
|
||||
Effect.ignore,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return Service.of({ get, refresh })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue