Skip to content

Commit 2280e5e

Browse files
authored
Merge pull request #486 from KxSystems/ee-progress
Unified query progress for KDB+ and Insights
2 parents 5fe1919 + e098c9b commit 2280e5e

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

src/classes/insightsConnection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ export class InsightsConnection {
403403
): Promise<any | undefined> {
404404
if (this.connected && this.connEndpoints) {
405405
const isTableView = ext.isResultsTabVisible;
406-
const queryMsg = isStarting
407-
? "Starting scratchpad..."
408-
: "Query is executing...";
409406
const scratchpadURL = new url.URL(
410407
this.connEndpoints.scratchpad.scratchpad,
411408
this.node.details.server,
@@ -453,10 +450,13 @@ export class InsightsConnection {
453450
},
454451
async (progress, token) => {
455452
token.onCancellationRequested(() => {
456-
kdbOutputLog(`User cancelled the Scrathpad execution.`, "WARNING");
453+
kdbOutputLog(`User cancelled the scratchpad execution.`, "WARNING");
457454
});
458455

459-
progress.report({ message: queryMsg });
456+
if (isStarting) {
457+
progress.report({ message: "Starting scratchpad..." });
458+
}
459+
460460
const spRes = await axios
461461
.post(scratchpadURL.toString(), body, {
462462
headers,

src/commands/dataSourceCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export async function runDataSource(
170170
const resultCount = typeof res === "string" ? "0" : res.rows.length;
171171
kdbOutputLog(`[DATASOURCE] Results: ${resultCount} rows`, "INFO");
172172
}
173-
writeQueryResultsToView(
173+
await writeQueryResultsToView(
174174
success ? res : res.error,
175175
query,
176176
connLabel,
@@ -185,7 +185,7 @@ export async function runDataSource(
185185
"INFO",
186186
);
187187
}
188-
writeQueryResultsToConsole(
188+
await writeQueryResultsToConsole(
189189
success ? res : res.error,
190190
query,
191191
connLabel,

src/commands/serverCommand.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import { readFileSync } from "fs-extra";
1515
import { join } from "path";
1616
import * as url from "url";
1717
import {
18+
CancellationToken,
1819
Position,
20+
ProgressLocation,
1921
Range,
2022
Uri,
2123
ViewColumn,
@@ -790,6 +792,37 @@ export async function executeQuery(
790792
isPython: boolean,
791793
isWorkbook: boolean,
792794
isFromConnTree?: boolean,
795+
): Promise<void> {
796+
await window.withProgress(
797+
{
798+
cancellable: true,
799+
location: ProgressLocation.Window,
800+
title: `Executing query (${executorName})`,
801+
},
802+
async (_progress, token) => {
803+
await _executeQuery(
804+
query,
805+
connLabel,
806+
executorName,
807+
context,
808+
isPython,
809+
isWorkbook,
810+
isFromConnTree,
811+
token,
812+
);
813+
},
814+
);
815+
}
816+
817+
async function _executeQuery(
818+
query: string,
819+
connLabel: string,
820+
executorName: string,
821+
context: string,
822+
isPython: boolean,
823+
isWorkbook: boolean,
824+
isFromConnTree?: boolean,
825+
token?: CancellationToken,
793826
): Promise<void> {
794827
const connMngService = new ConnectionManagementService();
795828
const queryConsole = ExecutionConsole.start();
@@ -842,9 +875,14 @@ export async function executeQuery(
842875
const endTime = Date.now();
843876
const duration = (endTime - startTime).toString();
844877

878+
/* istanbul ignore next */
879+
if (token?.isCancellationRequested) {
880+
return undefined;
881+
}
882+
845883
// set context for root nodes
846884
if (selectedConn instanceof InsightsConnection) {
847-
writeScratchpadResult(
885+
await writeScratchpadResult(
848886
results,
849887
query,
850888
connLabel,
@@ -875,7 +913,7 @@ export async function executeQuery(
875913
await setUriContent(uri, JSON.stringify(plot));
876914
}
877915
} else if (ext.isResultsTabVisible) {
878-
writeQueryResultsToView(
916+
await writeQueryResultsToView(
879917
results,
880918
query,
881919
connLabel,
@@ -888,7 +926,7 @@ export async function executeQuery(
888926
connVersion,
889927
);
890928
} else {
891-
writeQueryResultsToConsole(
929+
await writeQueryResultsToConsole(
892930
results,
893931
query,
894932
connLabel,
@@ -1123,7 +1161,7 @@ export async function exportConnections(connLabel?: string) {
11231161
}
11241162
}
11251163

1126-
export function writeQueryResultsToConsole(
1164+
export async function writeQueryResultsToConsole(
11271165
result: string | string[],
11281166
query: string,
11291167
connLabel: string,
@@ -1133,7 +1171,7 @@ export function writeQueryResultsToConsole(
11331171
isPython?: boolean,
11341172
duration?: string,
11351173
isFromConnTree?: boolean,
1136-
): void {
1174+
): Promise<void> {
11371175
const queryConsole = ExecutionConsole.start();
11381176
const isNonEmptyArray = Array.isArray(result) && result.length > 0;
11391177
const valueToDecode = isNonEmptyArray ? result[0] : result.toString();
@@ -1169,7 +1207,7 @@ export function writeQueryResultsToConsole(
11691207
}
11701208
}
11711209

1172-
export function writeQueryResultsToView(
1210+
export async function writeQueryResultsToView(
11731211
result: any,
11741212
query: string,
11751213
connLabel: string,
@@ -1180,8 +1218,8 @@ export function writeQueryResultsToView(
11801218
duration?: string,
11811219
isFromConnTree?: boolean,
11821220
connVersion?: number,
1183-
): void {
1184-
commands.executeCommand(
1221+
): Promise<void> {
1222+
await commands.executeCommand(
11851223
"kdb.resultsPanel.update",
11861224
result,
11871225
isInsights,
@@ -1204,7 +1242,7 @@ export function writeQueryResultsToView(
12041242
}
12051243
}
12061244

1207-
export function writeScratchpadResult(
1245+
export async function writeScratchpadResult(
12081246
result: ScratchpadResult,
12091247
query: string,
12101248
connLabel: string,
@@ -1213,7 +1251,7 @@ export function writeScratchpadResult(
12131251
isWorkbook: boolean,
12141252
duration: string,
12151253
connVersion: number,
1216-
): void {
1254+
): Promise<void> {
12171255
let errorMsg;
12181256

12191257
if (result.error) {
@@ -1226,7 +1264,7 @@ export function writeScratchpadResult(
12261264
}
12271265

12281266
if (ext.isResultsTabVisible) {
1229-
writeQueryResultsToView(
1267+
await writeQueryResultsToView(
12301268
errorMsg ?? result,
12311269
query,
12321270
connLabel,
@@ -1239,7 +1277,7 @@ export function writeScratchpadResult(
12391277
connVersion,
12401278
);
12411279
} else {
1242-
writeQueryResultsToConsole(
1280+
await writeQueryResultsToConsole(
12431281
errorMsg ?? result.data,
12441282
query,
12451283
connLabel,

0 commit comments

Comments
 (0)