Skip to content

Commit ba78657

Browse files
committed
Refactor environment and kernel assignment
Signed-off-by: Tomas Kislan <[email protected]>
1 parent 09742c9 commit ba78657

File tree

4 files changed

+118
-174
lines changed

4 files changed

+118
-174
lines changed

src/kernels/deepnote/environments/deepnoteEnvironmentManager.node.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { injectable, inject, named } from 'inversify';
1+
import { injectable, inject, named, optional } from 'inversify';
22
import { EventEmitter, Uri, CancellationToken, l10n } from 'vscode';
33
import { generateUuid as uuid } from '../../../platform/common/uuid';
4-
import { IExtensionContext, IOutputChannel } from '../../../platform/common/types';
4+
import { IConfigurationService, IExtensionContext, IOutputChannel } from '../../../platform/common/types';
55
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
66
import { logger } from '../../../platform/logging';
77
import { DeepnoteEnvironmentStorage } from './deepnoteEnvironmentStorage.node';
@@ -11,17 +11,27 @@ import {
1111
DeepnoteEnvironmentWithStatus,
1212
EnvironmentStatus
1313
} from './deepnoteEnvironment';
14-
import { IDeepnoteEnvironmentManager, IDeepnoteServerStarter, IDeepnoteToolkitInstaller } from '../types';
14+
import {
15+
IDeepnoteEnvironmentManager,
16+
IDeepnoteServerProvider,
17+
IDeepnoteServerStarter,
18+
IDeepnoteToolkitInstaller
19+
} from '../types';
1520
import { Cancellation } from '../../../platform/common/cancellation';
1621
import { STANDARD_OUTPUT_CHANNEL } from '../../../platform/common/constants';
22+
import { IJupyterRequestAgentCreator, IJupyterRequestCreator } from '../../jupyter/types';
1723

1824
/**
1925
* Manager for Deepnote kernel environments.
2026
* Handles CRUD operations and server lifecycle management.
2127
*/
2228
@injectable()
2329
export class DeepnoteEnvironmentManager implements IExtensionSyncActivationService, IDeepnoteEnvironmentManager {
30+
// Track server handles per notebook URI for cleanup
31+
// private readonly notebookServerHandles = new Map<string, string>();
32+
2433
private environments: Map<string, DeepnoteEnvironment> = new Map();
34+
private tmpStartingServers: Map<string, boolean> = new Map();
2535
private readonly _onDidChangeEnvironments = new EventEmitter<void>();
2636
public readonly onDidChangeEnvironments = this._onDidChangeEnvironments.event;
2737
private initializationPromise: Promise<void> | undefined;
@@ -31,6 +41,12 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
3141
@inject(DeepnoteEnvironmentStorage) private readonly storage: DeepnoteEnvironmentStorage,
3242
@inject(IDeepnoteToolkitInstaller) private readonly toolkitInstaller: IDeepnoteToolkitInstaller,
3343
@inject(IDeepnoteServerStarter) private readonly serverStarter: IDeepnoteServerStarter,
44+
@inject(IDeepnoteServerProvider) private readonly serverProvider: IDeepnoteServerProvider,
45+
@inject(IJupyterRequestCreator) private readonly requestCreator: IJupyterRequestCreator,
46+
@inject(IJupyterRequestAgentCreator)
47+
@optional()
48+
private readonly requestAgentCreator: IJupyterRequestAgentCreator | undefined,
49+
@inject(IConfigurationService) private readonly configService: IConfigurationService,
3450
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly outputChannel: IOutputChannel
3551
) {}
3652

@@ -135,6 +151,8 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
135151
let status: EnvironmentStatus;
136152
if (config.serverInfo) {
137153
status = EnvironmentStatus.Running;
154+
} else if (this.tmpStartingServers.get(id)) {
155+
status = EnvironmentStatus.Starting;
138156
} else {
139157
status = EnvironmentStatus.Stopped;
140158
}
@@ -207,6 +225,9 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
207225
throw new Error(`Environment not found: ${id}`);
208226
}
209227

228+
this.tmpStartingServers.set(id, true);
229+
this._onDidChangeEnvironments.fire();
230+
210231
try {
211232
logger.info(`Ensuring server is running for environment: ${config.name} (${id})`);
212233

@@ -239,6 +260,8 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
239260
} catch (error) {
240261
logger.error(`Failed to start server for environment: ${config.name} (${id})`, error);
241262
throw error;
263+
} finally {
264+
this.tmpStartingServers.delete(id);
242265
}
243266
}
244267

src/kernels/deepnote/environments/deepnoteEnvironmentPicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class DeepnoteEnvironmentPicker {
5757
});
5858

5959
if (!selected) {
60+
logger.info('User cancelled environment selection');
6061
return undefined; // User cancelled
6162
}
6263

src/kernels/deepnote/environments/deepnoteEnvironmentsView.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export class DeepnoteEnvironmentsView implements Disposable {
491491

492492
// Force rebuild the controller with the new environment
493493
// This clears cached metadata and creates a fresh controller.
494-
await this.kernelAutoSelector.rebuildController(activeNotebook);
494+
await this.kernelAutoSelector.ensureKernelSelected(activeNotebook);
495495

496496
logger.info(`Successfully switched to environment ${selectedEnvironmentId}`);
497497
}

0 commit comments

Comments
 (0)