mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-15 01:03:24 +00:00
refactor(core): move wellknown refresh to config
This commit is contained in:
parent
e4a16830f1
commit
a7cf21e157
3 changed files with 20 additions and 16 deletions
|
|
@ -367,6 +367,23 @@ const layer = Layer.effect(
|
|||
),
|
||||
Effect.forkScoped({ startImmediately: true }),
|
||||
)
|
||||
yield* Effect.sleep("10 minutes").pipe(
|
||||
Effect.andThen(
|
||||
Effect.suspend(() => {
|
||||
if (!wellknown.snapshot().length) return Effect.void
|
||||
return Effect.gen(function* () {
|
||||
const changed = yield* wellknown.refresh().pipe(
|
||||
Effect.catch((error) =>
|
||||
Effect.logWarning("failed to refresh wellknown manifests", { error }).pipe(Effect.as(false)),
|
||||
),
|
||||
)
|
||||
if (!changed) yield* reload()
|
||||
}).pipe(Effect.catchCause((cause) => Effect.logWarning("failed to refresh wellknown config", { cause })))
|
||||
}),
|
||||
),
|
||||
Effect.forever,
|
||||
Effect.forkScoped({ startImmediately: true }),
|
||||
)
|
||||
yield* reconcile(initial)
|
||||
|
||||
return Service.of({
|
||||
|
|
|
|||
|
|
@ -137,23 +137,14 @@ const layer = Layer.effect(
|
|||
)
|
||||
const next = new Map(entries.map((entry) => [entry.origin, entry]))
|
||||
const changed = !isDeepStrictEqual(Ref.getUnsafe(cache), next)
|
||||
if (changed) yield* Ref.set(cache, next)
|
||||
if (!changed) return false
|
||||
yield* Ref.set(cache, next)
|
||||
yield* events.publish(Event.Updated, {})
|
||||
return changed
|
||||
return true
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
yield* Effect.sleep("10 minutes").pipe(
|
||||
Effect.andThen(
|
||||
refresh().pipe(
|
||||
Effect.catch((error) => Effect.logWarning("failed to refresh wellknown manifests", { error })),
|
||||
),
|
||||
),
|
||||
Effect.forever,
|
||||
Effect.forkScoped({ startImmediately: true }),
|
||||
)
|
||||
|
||||
return Service.of({
|
||||
entries: load,
|
||||
snapshot: () => Array.from(Ref.getUnsafe(cache).values()),
|
||||
|
|
|
|||
|
|
@ -104,11 +104,7 @@ serviceIt.live("refreshes changed manifests", () =>
|
|||
const wellknown = yield* WellKnown.Service
|
||||
const events = yield* EventV2.Service
|
||||
yield* wellknown.add(server.url.origin)
|
||||
const refreshed = yield* events
|
||||
.subscribe(WellKnown.Event.Updated)
|
||||
.pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped)
|
||||
expect(yield* wellknown.refresh()).toBe(false)
|
||||
expect(yield* Fiber.join(refreshed)).toHaveLength(1)
|
||||
|
||||
const changed = yield* events
|
||||
.subscribe(WellKnown.Event.Updated)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue