Skip to content

Commit 6c1ec09

Browse files
committed
fix localstack instance status tracker
1 parent effc292 commit 6c1ec09

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

src/utils/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { createOnceImmediate } from "./once-immediate.ts";
22

3-
export type Callback<T> = (value: T) => Promise<void> | void;
3+
export type Callback<T> = (value: T | undefined) => Promise<void> | void;
44

55
export interface ValueEmitter<T> {
66
value(): T | undefined;
7-
setValue(value: T): void;
7+
setValue(value: T | undefined): void;
88
onChange(callback: Callback<T>): void;
99
}
1010

1111
export function createValueEmitter<T>(): ValueEmitter<T> {
12-
let currentValue: T;
12+
let currentValue: T | undefined;
1313
const callbacks: Callback<T>[] = [];
1414

1515
const emit = createOnceImmediate(async () => {

src/utils/localstack-instance.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function createLocalStackInstanceStatusTracker(
6161
});
6262

6363
status.onChange((newStatus) => {
64-
outputChannel.trace(`[localstack-status] localstack=${newStatus}`);
64+
outputChannel.trace(`[localstack-instances-status] status=${newStatus}`);
6565

6666
if (newStatus === "running") {
6767
healthCheckStatusTracker.stop();
@@ -89,9 +89,11 @@ export function createLocalStackInstanceStatusTracker(
8989
return status.value();
9090
},
9191
forceContainerStatus(newContainerStatus) {
92-
if (containerStatus !== newContainerStatus) {
93-
containerStatus = newContainerStatus;
94-
deriveStatus();
92+
containerStatus = newContainerStatus;
93+
if (newContainerStatus === "running") {
94+
status.setValue("starting");
95+
} else if (newContainerStatus === "stopping") {
96+
status.setValue("stopping");
9597
}
9698
},
9799
onChange(callback) {
@@ -107,24 +109,37 @@ function getLocalStackStatus(
107109
containerStatus: LocalStackContainerStatus | undefined,
108110
healthStatus: HealthStatus | undefined,
109111
previousStatus?: LocalStackInstanceStatus,
110-
): LocalStackInstanceStatus {
111-
if (containerStatus === "running") {
112-
if (healthStatus === "healthy") {
113-
return "running";
114-
} else {
115-
// When the LS container is running, and the health check fails:
116-
// - If the previous status was "running", we are likely stopping LS
117-
// - If the previous status was "stopping", we are still stopping LS
118-
if (previousStatus === "running" || previousStatus === "stopping") {
119-
return "stopping";
120-
}
121-
return "starting";
112+
): LocalStackInstanceStatus | undefined {
113+
// There's no LS container status yet, so can't derive LS instance status.
114+
if (containerStatus === undefined) {
115+
return undefined;
116+
}
117+
118+
if (containerStatus === "running" && healthStatus === "healthy") {
119+
return "running";
120+
}
121+
122+
if (containerStatus === "running" && healthStatus === "unhealthy") {
123+
// When the LS container is running, and the health check fails:
124+
// - If the previous status was "running", we are likely stopping LS
125+
// - If the previous status was "stopping", we are still stopping LS
126+
if (previousStatus === "running" || previousStatus === "stopping") {
127+
return "stopping";
122128
}
123-
} else if (containerStatus === "stopping") {
129+
130+
return "starting";
131+
}
132+
133+
if (containerStatus === "running" && healthStatus === undefined) {
134+
// return previousStatus;
135+
return undefined;
136+
}
137+
138+
if (containerStatus === "stopping") {
124139
return "stopping";
125-
} else {
126-
return "stopped";
127140
}
141+
142+
return "stopped";
128143
}
129144

130145
type HealthStatus = "healthy" | "unhealthy";

0 commit comments

Comments
 (0)