Skip to content

Commit

Permalink
use provider.onDidRegisterContainerConnection to know when providers …
Browse files Browse the repository at this point in the history
…are up
  • Loading branch information
feloy committed Jan 31, 2024
1 parent 44c74bb commit 0357897
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/backend/src/managers/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export class PlayGroundManager {
}

async adoptRunningPlaygrounds() {
provider.onDidRegisterContainerConnection(async () => {
await this.doAdoptRunningPlaygrounds();
});
// Do it now in case providers are already registered
await this.doAdoptRunningPlaygrounds();
}

private async doAdoptRunningPlaygrounds() {
const containers = await containerEngine.listContainers();
const playgroundContainers = containers.filter(
c => LABEL_MODEL_ID in c.Labels && LABEL_MODEL_PORT in c.Labels && c.State === 'running',
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/studio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ vi.mock('@podman-desktop/api', async () => {
onEvent: vi.fn(),
listContainers: mocks.listContainers,
},
provider: {
onDidRegisterContainerConnection: vi.fn(),
},
};
});

Expand Down

0 comments on commit 0357897

Please sign in to comment.