refactor(core): move wellknown refresh to config

This commit is contained in:
Dax Raad
2026-07-16 14:32:46 -04:00
parent e4a16830f1
commit a7cf21e157
3 changed files with 20 additions and 16 deletions
+17
View File
@@ -367,6 +367,23 @@ const layer = Layer.effect(
), ),
Effect.forkScoped({ startImmediately: true }), 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) yield* reconcile(initial)
return Service.of({ return Service.of({
+3 -12
View File
@@ -137,23 +137,14 @@ const layer = Layer.effect(
) )
const next = new Map(entries.map((entry) => [entry.origin, entry])) const next = new Map(entries.map((entry) => [entry.origin, entry]))
const changed = !isDeepStrictEqual(Ref.getUnsafe(cache), next) 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, {}) 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({ return Service.of({
entries: load, entries: load,
snapshot: () => Array.from(Ref.getUnsafe(cache).values()), snapshot: () => Array.from(Ref.getUnsafe(cache).values()),
-4
View File
@@ -104,11 +104,7 @@ serviceIt.live("refreshes changed manifests", () =>
const wellknown = yield* WellKnown.Service const wellknown = yield* WellKnown.Service
const events = yield* EventV2.Service const events = yield* EventV2.Service
yield* wellknown.add(server.url.origin) 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* wellknown.refresh()).toBe(false)
expect(yield* Fiber.join(refreshed)).toHaveLength(1)
const changed = yield* events const changed = yield* events
.subscribe(WellKnown.Event.Updated) .subscribe(WellKnown.Event.Updated)