Skip to content

Commit

Permalink
Merge pull request #219 from KxSystems/KXI-33737
Browse files Browse the repository at this point in the history
KXI-33737: Data Sources can be executed multiple times concurrently
  • Loading branch information
ecmel authored Dec 21, 2023
2 parents 6db03af + cbad1e1 commit 2b19bcf
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 41 deletions.
91 changes: 50 additions & 41 deletions src/commands/dataSourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,52 +214,61 @@ export async function populateScratchpad(
export async function runDataSource(
dataSourceForm: DataSourceFiles
): Promise<void> {
Object.assign(ext.insightsMeta, await getMeta());
if (!ext.insightsMeta.assembly) {
ext.outputChannel.appendLine(
`To run a datasource you need to be connected to an Insights server`
);
window.showErrorMessage(
"To run a datasource you need to be connected to an Insights server"
);
if (DataSourcesPanel.running) {
return;
}
DataSourcesPanel.running = true;

dataSourceForm.insightsNode = getConnectedInsightsNode();
const fileContent = dataSourceForm;
try {
Object.assign(ext.insightsMeta, await getMeta());
if (!ext.insightsMeta.assembly) {
ext.outputChannel.appendLine(
`To run a datasource you need to be connected to an Insights server`
);
window.showErrorMessage(
"To run a datasource you need to be connected to an Insights server"
);
return;
}

let res: any;
const selectedType = getSelectedType(fileContent);
ext.isDatasourceExecution = true;
switch (selectedType) {
case "API":
res = await runApiDataSource(fileContent);
break;
case "QSQL":
res = await runQsqlDataSource(fileContent);
break;
case "SQL":
default:
res = await runSqlDataSource(fileContent);
break;
}
dataSourceForm.insightsNode = getConnectedInsightsNode();
const fileContent = dataSourceForm;

let res: any;
const selectedType = getSelectedType(fileContent);
ext.isDatasourceExecution = true;
switch (selectedType) {
case "API":
res = await runApiDataSource(fileContent);
break;
case "QSQL":
res = await runQsqlDataSource(fileContent);
break;
case "SQL":
default:
res = await runSqlDataSource(fileContent);
break;
}

ext.isDatasourceExecution = false;
if (res.error) {
window.showErrorMessage(res.error);
} else if (ext.resultsViewProvider.isVisible()) {
writeQueryResultsToView(
res,
getQuery(fileContent, selectedType),
selectedType
);
} else {
const resString = arrayToTable(res);
writeQueryResultsToConsole(
resString,
getQuery(fileContent, selectedType),
selectedType
);
ext.isDatasourceExecution = false;
if (res.error) {
window.showErrorMessage(res.error);
} else if (ext.resultsViewProvider.isVisible()) {
writeQueryResultsToView(
res,
getQuery(fileContent, selectedType),
selectedType
);
} else {
const resString = arrayToTable(res);
writeQueryResultsToConsole(
resString,
getQuery(fileContent, selectedType),
selectedType
);
}
} finally {
DataSourcesPanel.running = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export type DataSourceMessage = {
insightsMeta: MetaObjectPayload;
dataSourceName: string;
dataSourceFile: DataSourceFiles;
running?: boolean;
};
18 changes: 18 additions & 0 deletions src/panels/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { InsightsNode } from "../services/kdbTreeProvider";
import { getNonce } from "../utils/getNonce";
import { getUri } from "../utils/getUri";

let running = false;

export class DataSourcesPanel {
public static currentPanel: DataSourcesPanel | undefined;
private uri;
Expand Down Expand Up @@ -96,6 +98,22 @@ export class DataSourcesPanel {
}
}

public static set running(flag: boolean) {
running = flag;
const panel = DataSourcesPanel.currentPanel;
if (panel) {
panel.status();
}
}

public static get running() {
return running;
}

public status() {
this._panel.webview.postMessage({ running });
}

public refresh() {
DataSourcesPanel.render(this.uri, this.dataSourceFile);
}
Expand Down
7 changes: 7 additions & 0 deletions src/webview/components/kdbDataSourceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class KdbDataSourceView extends LitElement {
@state() declare qsqlTarget: string;
@state() declare qsql: string;
@state() declare sql: string;
@state() declare running: boolean;

constructor() {
super();
Expand Down Expand Up @@ -91,6 +92,7 @@ export class KdbDataSourceView extends LitElement {
this.qsqlTarget = "";
this.qsql = "";
this.sql = "";
this.running = false;
}

connectedCallback() {
Expand All @@ -105,6 +107,10 @@ export class KdbDataSourceView extends LitElement {

private message = (event: MessageEvent<DataSourceMessage>) => {
const params = event.data;
if (params.running !== undefined) {
this.running = params.running;
return;
}
const ds = params.dataSourceFile;
this.isInsights = params.isInsights;
this.isMetaLoaded = !!params.insightsMeta.dap;
Expand Down Expand Up @@ -930,6 +936,7 @@ export class KdbDataSourceView extends LitElement {
appearance="secondary"
class="grow"
@click="${this.run}"
?disabled="${this.running}"
>Run</vscode-button
>
</div>
Expand Down
9 changes: 9 additions & 0 deletions test/suite/webview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ describe("KdbDataSourceView", () => {
});
});

describe("message", () => {
it("should update status", () => {
view["message"](<MessageEvent<DataSourceMessage>>{
data: { running: true },
});
assert.strictEqual(view.running, true);
});
});

describe("selectTab", () => {
it("should return the selected tab", () => {
sinon.stub(view, "selectedType").value("DEFAULT");
Expand Down

0 comments on commit 2b19bcf

Please sign in to comment.