-
Notifications
You must be signed in to change notification settings - Fork 516
test(stack): qualify native Postgres, Auth, and PostgREST core #6379
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
base: juliengoux/cli-2113-stack-qualify-the-complete-slim-docker-service-graph
Are you sure you want to change the base?
Changes from all commits
f24be1b
d17f9bf
41be775
ccbf5c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,10 @@ export const localStackLayer = ( | |
| config.functions === false ? undefined : config.functions, | ||
| ); | ||
| const edgeRuntimeConfigRef = yield* Ref.make(config.edgeRuntime); | ||
| // A whole-stack stop changes the orchestrator desired state for every running service to | ||
| // `stopped`. Keep that lifecycle intent separate from an explicit service stop so a later | ||
| // lazy activation can restore only services that were running before the whole-stack stop. | ||
| const wholeStackStoppedServicesRef = yield* Ref.make<ReadonlySet<ServiceName>>(new Set()); | ||
| const disposedSignal = yield* Deferred.make<void>(); | ||
| const lifecycleLock = Semaphore.makeUnsafe(1); | ||
| const projectionLock = Semaphore.makeUnsafe(1); | ||
|
|
@@ -626,6 +630,22 @@ export const localStackLayer = ( | |
| const withLifecycleLock = lifecycleLock.withPermit; | ||
| const syncRuntimeProjectedStates = (runtime: RuntimeState) => | ||
| syncProjectedStates(runtime.orchestrator, runtime.serviceProjection); | ||
| const clearWholeStackStopAllowance = (services: ReadonlyArray<ServiceName>) => | ||
| Ref.update(wholeStackStoppedServicesRef, (current) => { | ||
| const next = new Set(current); | ||
| for (const service of services) next.delete(service); | ||
| return next; | ||
| }); | ||
| const wholeStackStopAllowance = Ref.get(wholeStackStoppedServicesRef); | ||
| const rememberWholeStackStoppedServices = (runtime: RuntimeState) => | ||
| Effect.gen(function* () { | ||
| const running = (yield* runtime.orchestrator.getAllStates).flatMap((state) => { | ||
| if (state.desired !== "running") return []; | ||
| const service = SERVICE_NAMES.find((candidate) => candidate === state.name); | ||
| return service !== undefined && enabledServices.includes(service) ? [service] : []; | ||
| }); | ||
| yield* Ref.set(wholeStackStoppedServicesRef, new Set(running)); | ||
| }); | ||
| const serviceStartOptions = { | ||
| // Reservation may yield while disposal flips the lifecycle state. | ||
| beforeStart: (name: string) => | ||
|
|
@@ -736,6 +756,11 @@ export const localStackLayer = ( | |
| return yield* new StackNotRunningError({ phase }); | ||
| } | ||
| }); | ||
| const clearWholeStackStopAllowanceAfterSuccess = (services: ReadonlyArray<ServiceName>) => | ||
| Effect.gen(function* () { | ||
| yield* requireRunningPhase; | ||
| yield* clearWholeStackStopAllowance(services); | ||
| }).pipe(lifecycleLock.withPermit); | ||
| const requireMutable = (operation: string) => | ||
| Effect.suspend(() => | ||
| disposed || disposing | ||
|
|
@@ -849,6 +874,9 @@ export const localStackLayer = ( | |
| // Close the race with a concurrent stack stop before taking | ||
| // the lock-free healthy-request fast path. | ||
| yield* requireRunningPhase; | ||
| yield* clearWholeStackStopAllowanceAfterSuccess( | ||
| lifecycleTargetsForService(enabledServices, service), | ||
| ); | ||
| return; | ||
| } | ||
| if (existing !== undefined) { | ||
|
|
@@ -859,14 +887,18 @@ export const localStackLayer = ( | |
| activationReadinessPolicy(service, config.readiness, config.readinessSource), | ||
| ), | ||
| ); | ||
| yield* clearWholeStackStopAllowanceAfterSuccess( | ||
| lifecycleTargetsForService(enabledServices, service), | ||
| ); | ||
| return; | ||
| } | ||
| yield* prepareServices([service]); | ||
| const started = yield* Effect.gen(function* () { | ||
| yield* requireRunningPhase; | ||
| const concurrentlyStarted = yield* inspectStartedTargets(service); | ||
| if (concurrentlyStarted !== undefined) return concurrentlyStarted; | ||
| return yield* beginStartTargets(service, new Set()); | ||
| const allowedWholeStackStops = yield* wholeStackStopAllowance; | ||
| return yield* beginStartTargets(service, allowedWholeStackStops); | ||
| }).pipe(withLifecycleLock); | ||
| yield* waitForTargets(started).pipe((effect) => | ||
| withReadinessPolicy( | ||
|
|
@@ -875,6 +907,9 @@ export const localStackLayer = ( | |
| activationReadinessPolicy(service, config.readiness, config.readinessSource), | ||
| ), | ||
| ); | ||
| yield* clearWholeStackStopAllowanceAfterSuccess( | ||
| lifecycleTargetsForService(enabledServices, service), | ||
| ); | ||
| }).pipe(cleanupOnReadinessFailure); | ||
|
|
||
| const stack = { | ||
|
|
@@ -933,6 +968,7 @@ export const localStackLayer = ( | |
| (effect) => withReadinessPolicy(effect, "stack"), | ||
| ); | ||
| yield* syncRuntimeProjectedStates(runtime); | ||
| yield* clearWholeStackStopAllowance(["postgres", ...eager]); | ||
| } else { | ||
| yield* prepareServices(enabledServices); | ||
| yield* requireMutable("start"); | ||
|
|
@@ -942,6 +978,7 @@ export const localStackLayer = ( | |
| withReadinessPolicy(effect, "stack"), | ||
| ); | ||
| yield* syncRuntimeProjectedStates(runtime); | ||
| yield* clearWholeStackStopAllowance(enabledServices); | ||
| } | ||
| yield* requireMutable("start"); | ||
| yield* Ref.set(phaseRef, "running"); | ||
|
|
@@ -956,10 +993,16 @@ export const localStackLayer = ( | |
| if (disposed) { | ||
| return; | ||
| } | ||
| const phase = yield* Ref.get(phaseRef); | ||
| if (phase === "stopped") { | ||
| return; | ||
| } | ||
| if (runtimeState === undefined) { | ||
| yield* Ref.set(wholeStackStoppedServicesRef, new Set()); | ||
| yield* Ref.set(phaseRef, "stopped"); | ||
| return; | ||
| } | ||
| yield* rememberWholeStackStoppedServices(runtimeState); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an Effect caller interrupts AGENTS.md reference: AGENTS.md:L160-L167 Useful? React with 👍 / 👎. |
||
| yield* Ref.set(phaseRef, "stopping"); | ||
| yield* runtimeState.orchestrator.stop; | ||
| yield* Ref.set(phaseRef, "stopped"); | ||
|
|
@@ -974,12 +1017,19 @@ export const localStackLayer = ( | |
| const started = yield* Effect.gen(function* () { | ||
| yield* requireMutable(`start service ${name}`); | ||
| yield* requireRunningPhase; | ||
| const allowedWholeStackStops = yield* wholeStackStopAllowance; | ||
| return yield* beginStartTargets( | ||
| service, | ||
| new Set(lifecycleTargetsForService(enabledServices, service)), | ||
| new Set([ | ||
| ...allowedWholeStackStops, | ||
| ...lifecycleTargetsForService(enabledServices, service), | ||
| ]), | ||
| ); | ||
| }).pipe(withLifecycleLock); | ||
| yield* waitForTargets(started).pipe((effect) => withReadinessPolicy(effect, name)); | ||
| yield* clearWholeStackStopAllowanceAfterSuccess( | ||
| lifecycleTargetsForService(enabledServices, service), | ||
| ); | ||
| }).pipe(cleanupOnReadinessFailure), | ||
| stopService: (name) => | ||
| Effect.gen(function* () { | ||
|
|
@@ -993,6 +1043,9 @@ export const localStackLayer = ( | |
| ).toReversed()) { | ||
| yield* runtime.orchestrator.stopService(target); | ||
| } | ||
| yield* clearWholeStackStopAllowance( | ||
| lifecycleTargetsForService(enabledServices, service), | ||
| ); | ||
| // Settle the public projection before returning so callers observe | ||
| // the stop immediately, matching the start/restart/waitReady paths. | ||
| yield* syncRuntimeProjectedStates(runtime); | ||
|
|
@@ -1011,6 +1064,7 @@ export const localStackLayer = ( | |
| return { runtime, targets: [service] }; | ||
| }).pipe(withLifecycleLock); | ||
| yield* waitForTargets(started).pipe((effect) => withReadinessPolicy(effect, name)); | ||
| yield* clearWholeStackStopAllowanceAfterSuccess([service]); | ||
| }).pipe(cleanupOnReadinessFailure), | ||
| reloadFunctions: (opts) => | ||
| Effect.gen(function* () { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.