Skip to content

Commit 96add94

Browse files
committed
feat: reflect localstack status immediately after running start and stop commands
Makes the status bar display that LS is either starting or stopping immediately after executing the respective LS commands.
1 parent c3b05a9 commit 96add94

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/utils/localstack-status.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export type LocalStackStatus = "starting" | "running" | "stopping" | "stopped";
1111

1212
export interface LocalStackStatusTracker extends Disposable {
1313
status(): LocalStackStatus;
14+
// setStatus(status: LocalStackStatus): void;
15+
forceStarting(): void;
16+
forceStopping(): void;
1417
onChange(callback: (status: LocalStackStatus) => void): void;
1518
}
1619

@@ -22,30 +25,36 @@ export async function createLocalStackStatusTracker(
2225
outputChannel: LogOutputChannel,
2326
timeTracker: TimeTracker,
2427
): Promise<LocalStackStatusTracker> {
28+
let containerStatus: ContainerStatus | undefined;
2529
let status: LocalStackStatus | undefined;
2630
const emitter = createEmitter<LocalStackStatus>(outputChannel);
2731

2832
let healthCheck: boolean | undefined;
2933

30-
const updateStatus = () => {
31-
const newStatus = getLocalStackStatus(
32-
containerStatusTracker.status(),
33-
healthCheck,
34-
);
34+
const setStatus = (newStatus: LocalStackStatus) => {
3535
if (status !== newStatus) {
3636
status = newStatus;
37+
outputChannel.debug(`[localstack.status]: ${status}`);
3738
void emitter.emit(status);
3839
}
3940
};
4041

41-
containerStatusTracker.onChange(() => {
42-
updateStatus();
42+
const deriveStatus = () => {
43+
const newStatus = getLocalStackStatus(containerStatus, healthCheck);
44+
setStatus(newStatus);
45+
};
46+
47+
containerStatusTracker.onChange((newContainerStatus) => {
48+
if (containerStatus !== newContainerStatus) {
49+
containerStatus = newContainerStatus;
50+
deriveStatus();
51+
}
4352
});
4453

4554
let healthCheckTimeout: NodeJS.Timeout | undefined;
4655
const startHealthCheck = async () => {
4756
healthCheck = await fetchHealth();
48-
updateStatus();
57+
deriveStatus();
4958
healthCheckTimeout = setTimeout(() => void startHealthCheck(), 1_000);
5059
};
5160

@@ -58,6 +67,18 @@ export async function createLocalStackStatusTracker(
5867
// biome-ignore lint/style/noNonNullAssertion: false positive
5968
return status!;
6069
},
70+
forceStarting() {
71+
if (containerStatus !== "running") {
72+
containerStatus = "running";
73+
deriveStatus();
74+
}
75+
},
76+
forceStopping() {
77+
if (containerStatus !== "stopping") {
78+
containerStatus = "stopping";
79+
deriveStatus();
80+
}
81+
},
6182
onChange(callback) {
6283
emitter.on(callback);
6384
if (status) {

0 commit comments

Comments
 (0)