Skip to content

Commit a58c3f3

Browse files
committed
unified query progress
1 parent e28a293 commit a58c3f3

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

src/classes/insightsConnection.ts

Lines changed: 4 additions & 4 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,
@@ -456,7 +453,10 @@ export class InsightsConnection {
456453
kdbOutputLog(`User cancelled the Scrathpad 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: 49 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,13 @@ export async function executeQuery(
842875
const endTime = Date.now();
843876
const duration = (endTime - startTime).toString();
844877

878+
if (token?.isCancellationRequested) {
879+
return undefined;
880+
}
881+
845882
// set context for root nodes
846883
if (selectedConn instanceof InsightsConnection) {
847-
writeScratchpadResult(
884+
await writeScratchpadResult(
848885
results,
849886
query,
850887
connLabel,
@@ -875,7 +912,7 @@ export async function executeQuery(
875912
await setUriContent(uri, JSON.stringify(plot));
876913
}
877914
} else if (ext.isResultsTabVisible) {
878-
writeQueryResultsToView(
915+
await writeQueryResultsToView(
879916
results,
880917
query,
881918
connLabel,
@@ -888,7 +925,7 @@ export async function executeQuery(
888925
connVersion,
889926
);
890927
} else {
891-
writeQueryResultsToConsole(
928+
await writeQueryResultsToConsole(
892929
results,
893930
query,
894931
connLabel,
@@ -1123,7 +1160,7 @@ export async function exportConnections(connLabel?: string) {
11231160
}
11241161
}
11251162

1126-
export function writeQueryResultsToConsole(
1163+
export async function writeQueryResultsToConsole(
11271164
result: string | string[],
11281165
query: string,
11291166
connLabel: string,
@@ -1133,7 +1170,7 @@ export function writeQueryResultsToConsole(
11331170
isPython?: boolean,
11341171
duration?: string,
11351172
isFromConnTree?: boolean,
1136-
): void {
1173+
): Promise<void> {
11371174
const queryConsole = ExecutionConsole.start();
11381175
const isNonEmptyArray = Array.isArray(result) && result.length > 0;
11391176
const valueToDecode = isNonEmptyArray ? result[0] : result.toString();
@@ -1169,7 +1206,7 @@ export function writeQueryResultsToConsole(
11691206
}
11701207
}
11711208

1172-
export function writeQueryResultsToView(
1209+
export async function writeQueryResultsToView(
11731210
result: any,
11741211
query: string,
11751212
connLabel: string,
@@ -1180,8 +1217,8 @@ export function writeQueryResultsToView(
11801217
duration?: string,
11811218
isFromConnTree?: boolean,
11821219
connVersion?: number,
1183-
): void {
1184-
commands.executeCommand(
1220+
): Promise<void> {
1221+
await commands.executeCommand(
11851222
"kdb.resultsPanel.update",
11861223
result,
11871224
isInsights,
@@ -1204,7 +1241,7 @@ export function writeQueryResultsToView(
12041241
}
12051242
}
12061243

1207-
export function writeScratchpadResult(
1244+
export async function writeScratchpadResult(
12081245
result: ScratchpadResult,
12091246
query: string,
12101247
connLabel: string,
@@ -1213,7 +1250,7 @@ export function writeScratchpadResult(
12131250
isWorkbook: boolean,
12141251
duration: string,
12151252
connVersion: number,
1216-
): void {
1253+
): Promise<void> {
12171254
let errorMsg;
12181255

12191256
if (result.error) {
@@ -1226,7 +1263,7 @@ export function writeScratchpadResult(
12261263
}
12271264

12281265
if (ext.isResultsTabVisible) {
1229-
writeQueryResultsToView(
1266+
await writeQueryResultsToView(
12301267
errorMsg ?? result,
12311268
query,
12321269
connLabel,
@@ -1239,7 +1276,7 @@ export function writeScratchpadResult(
12391276
connVersion,
12401277
);
12411278
} else {
1242-
writeQueryResultsToConsole(
1279+
await writeQueryResultsToConsole(
12431280
errorMsg ?? result.data,
12441281
query,
12451282
connLabel,

0 commit comments

Comments
 (0)