Skip to content

Commit

Permalink
Removed unused workercount (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 8, 2024
1 parent d80bec0 commit 223f731
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/dh/dhe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export async function createInteractiveConsoleQuery(
draftQuery.updateSchedule();
}

// type assertion gives us stronger type safety than the Promise<string>
// return type defined by the JS API types.
return dheClient.createQuery(draftQuery) as Promise<QuerySerial>;
}

Expand Down
2 changes: 2 additions & 0 deletions src/services/DhcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export class DhcService extends DhService<typeof DhcType, DhcType.CoreClient> {
} else if (authConfig.has(AUTH_HANDLER_TYPE_PSK)) {
this.coreCredentialsCache.set(this.serverUrl, async () => ({
type: AUTH_HANDLER_TYPE_PSK,
// TODO: Login flow UI should be a separate concern
// deephaven/vscode-deephaven/issues/151
token: await vscode.window.showInputBox({
placeHolder: 'Pre-Shared Key',
prompt: 'Enter your Deephaven pre-shared key',
Expand Down
79 changes: 31 additions & 48 deletions src/services/DheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class DheService implements IDheService {

private _clientPromise: Promise<EnterpriseClient | null> | null = null;
private _isConnected: boolean = false;
private _workerCount: number = 0;
private readonly _coreCredentialsCache: URLMap<
Lazy<DhcType.LoginCredentials>
>;
Expand All @@ -100,13 +99,6 @@ export class DheService implements IDheService {
return this._isConnected;
}

/**
* Number of workers created.
*/
get workerCount(): number {
return this._workerCount;
}

/**
* Initialize DHE client and login.
* @returns DHE client or null if initialization failed.
Expand Down Expand Up @@ -197,57 +189,48 @@ export class DheService implements IDheService {
tagId: UniqueID,
consoleType?: ConsoleType
): Promise<WorkerInfo> => {
this._workerCount += 1;

try {
const dheClient = await this.getClient(true);
if (dheClient == null) {
const msg =
'Failed to create worker because DHE client failed to initialize.';
logger.error(msg);
throw new Error(msg);
}

const dhe = await this._dheJsApiCache.get(this.serverUrl);

const querySerial = await createInteractiveConsoleQuery(
tagId,
dheClient,
consoleType
);
this._querySerialSet.add(querySerial);
const dheClient = await this.getClient(true);
if (dheClient == null) {
const msg =
'Failed to create worker because DHE client failed to initialize.';
logger.error(msg);
throw new Error(msg);
}

const workerInfo = await getWorkerInfoFromQuery(
tagId,
dhe,
dheClient,
querySerial
);
if (workerInfo == null) {
throw new Error('Failed to create worker.');
}
const dhe = await this._dheJsApiCache.get(this.serverUrl);

const querySerial = await createInteractiveConsoleQuery(
tagId,
dheClient,
consoleType
);
this._querySerialSet.add(querySerial);

const workerInfo = await getWorkerInfoFromQuery(
tagId,
dhe,
dheClient,
querySerial
);
if (workerInfo == null) {
throw new Error('Failed to create worker.');
}

const workerUrl = new URL(workerInfo.grpcUrl);
this._coreCredentialsCache.set(workerUrl, () =>
getWorkerCredentials(dheClient)
);
const workerUrl = new URL(workerInfo.grpcUrl);
this._coreCredentialsCache.set(workerUrl, () =>
getWorkerCredentials(dheClient)
);

this._workerInfoMap.set(workerInfo.grpcUrl, workerInfo);
this._workerInfoMap.set(workerInfo.grpcUrl, workerInfo);

return workerInfo;
} catch (err) {
this._workerCount -= 1;
throw err;
}
return workerInfo;
};

/**
* Delete a worker.
* @param workerUrl Worker URL to delete.
*/
deleteWorker = async (workerUrl: WorkerURL): Promise<void> => {
this._workerCount -= 1;

const workerInfo = this._workerInfoMap.get(workerUrl);
if (workerInfo == null) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/types/serviceTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export interface IDhService<TDH = unknown, TClient = unknown>
}

export interface IDheService extends ConnectionState, Disposable {
readonly workerCount: number;
getClient: (initializeIfNull: boolean) => Promise<EnterpriseClient | null>;
getWorkerInfo: (workerUrl: WorkerURL) => WorkerInfo | undefined;
createWorker: (
Expand Down

0 comments on commit 223f731

Please sign in to comment.