Skip to content

Commit 03c9ec6

Browse files
feloyaxel7083
andauthored
fix: make instructLabManager disposable (#2837)
* fix: make instructLabManager disposable Signed-off-by: Philippe Martin <[email protected]> * fix: add Implements Co-authored-by: axel7083 <[email protected]> Signed-off-by: Philippe Martin <[email protected]> --------- Signed-off-by: Philippe Martin <[email protected]> Co-authored-by: axel7083 <[email protected]>
1 parent 63067a4 commit 03c9ec6

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/backend/src/managers/instructlab/instructlabManager.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ beforeEach(() => {
6363
const containerRegistry = new ContainerRegistry();
6464
containerRegistry.init();
6565
instructlabManager = new InstructlabManager('', taskRegistry, podmanConnection, containerRegistry, telemetryMock);
66+
instructlabManager.init();
6667
taskRegistry.deleteByLabels({ trackingId: INSTRUCTLAB_CONTAINER_TRACKINGID });
6768
});
6869

packages/backend/src/managers/instructlab/instructlabManager.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
containerEngine,
2525
type ContainerProviderConnection,
2626
type ContainerCreateOptions,
27+
type Disposable,
2728
} from '@podman-desktop/api';
2829
import type { PodmanConnection, PodmanConnectionEvent } from '../podmanConnection';
2930
import instructlab_images from '../../assets/instructlab-images.json';
@@ -37,9 +38,10 @@ import { getRandomName } from '../../utils/randomUtils';
3738

3839
export const INSTRUCTLAB_CONTAINER_LABEL = 'ai-lab-instructlab-container';
3940

40-
export class InstructlabManager {
41+
export class InstructlabManager implements Disposable {
4142
#initialized: boolean;
4243
#containerId: string | undefined;
44+
#disposables: Disposable[];
4345

4446
constructor(
4547
private readonly appUserDirectory: string,
@@ -49,9 +51,18 @@ export class InstructlabManager {
4951
private telemetryLogger: TelemetryLogger,
5052
) {
5153
this.#initialized = false;
52-
this.podmanConnection.onPodmanConnectionEvent(this.watchMachineEvent.bind(this));
53-
this.containerRegistry.onStartContainerEvent(this.onStartContainerEvent.bind(this));
54-
this.containerRegistry.onStopContainerEvent(this.onStopContainerEvent.bind(this));
54+
this.#disposables = [];
55+
}
56+
57+
init(): void {
58+
this.#disposables.push(this.podmanConnection.onPodmanConnectionEvent(this.watchMachineEvent.bind(this)));
59+
this.#disposables.push(this.containerRegistry.onStartContainerEvent(this.onStartContainerEvent.bind(this)));
60+
this.#disposables.push(this.containerRegistry.onStopContainerEvent(this.onStopContainerEvent.bind(this)));
61+
}
62+
63+
dispose(): void {
64+
this.#disposables.forEach(disposable => disposable.dispose());
65+
this.#disposables = [];
5566
}
5667

5768
private async refreshInstructlabContainer(id?: string): Promise<void> {

packages/backend/src/studio.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ export class Studio {
300300
this.#containerRegistry,
301301
this.#telemetry,
302302
);
303+
this.#instructlabManager.init();
304+
this.#extensionContext.subscriptions.push(this.#instructlabManager);
303305

304306
/**
305307
* The recipe manage offer some andy methods to manage recipes, build get images etc.

0 commit comments

Comments
 (0)