Skip to content

Commit 63a3a7c

Browse files
committed
split dbt version check and dbt installed check
1 parent 03e9ac4 commit 63a3a7c

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

src/dbt_client/dbtCommandFactory.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@ export interface CommandProcessExecutionParams {
1313
}
1414

1515
export interface DBTCommand {
16-
commandAsString: string;
16+
commandAsString?: string;
1717
statusMessage: string;
1818
processExecutionParams: CommandProcessExecutionParams;
1919
focus?: boolean;
2020
}
2121

2222
@provideSingleton(DBTCommandFactory)
2323
export class DBTCommandFactory {
24+
createImportDBTCommand(): DBTCommand {
25+
return {
26+
statusMessage: "Detecting dbt installation...",
27+
processExecutionParams: {
28+
args: ["-c", 'import dbt.main; print("dbt is installed")'],
29+
},
30+
};
31+
}
32+
2433
createVersionCommand(): DBTCommand {
2534
return {
26-
commandAsString: "dbt --version",
2735
statusMessage: "Detecting dbt version...",
2836
processExecutionParams: {
2937
args: ["-c", this.dbtCommand("'--version'")],

src/dbt_client/index.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,36 @@ export class DBTClient implements Disposable {
9292

9393
async checkIfDBTIsInstalled(): Promise<void> {
9494
const checkDBTInstalledProcess = this.executeCommand(
95-
this.dbtCommandFactory.createVersionCommand()
95+
this.dbtCommandFactory.createImportDBTCommand()
9696
);
97+
98+
this.raiseDBTInstallationCheckEvent();
9799
try {
98-
this.raiseDBTInstallationCheckEvent();
99100
await checkDBTInstalledProcess.complete();
100-
checkDBTInstalledProcess.dispose();
101+
}catch(_) {
102+
this.raiseDBTNotInstalledEvent();
103+
return;
104+
}
105+
106+
const checkDBTVersionProcess = this.executeCommand(
107+
this.dbtCommandFactory.createVersionCommand()
108+
);
109+
const timeoutCmd = new Promise((resolve, _) => {
110+
setTimeout(resolve, 5000, 'Could not connect');
111+
});
112+
try {
113+
await Promise.race([
114+
checkDBTVersionProcess.complete(),
115+
timeoutCmd,
116+
]);
117+
checkDBTVersionProcess.dispose();
101118
} catch (err) {
102119
if (err.match(DBTClient.IS_INSTALLED)) {
103120
this.checkIfDBTIsUpToDate(err);
104121
return;
105122
}
106-
this.raiseDBTNotInstalledEvent();
107123
}
124+
this.raiseDBTVersionCouldNotBeDeterminedEvent();
108125
}
109126

110127
addCommandToQueue(command: DBTCommand) {
@@ -151,13 +168,17 @@ export class DBTClient implements Disposable {
151168
},
152169
});
153170
}
154-
this.writeEmitter.fire(
155-
`\r> Executing task: ${command.commandAsString}\n\r\n\r`
156-
);
157171

158-
if (command.focus) {
159-
this.terminal.show(true);
172+
if (command.commandAsString !== undefined) {
173+
this.writeEmitter.fire(
174+
`\r> Executing task: ${command.commandAsString}\n\r\n\r`
175+
);
176+
177+
if (command.focus) {
178+
this.terminal.show(true);
179+
}
160180
}
181+
161182
return this.commandProcessExecutionFactory.createCommandProcessExecution(
162183
this.pythonPath!,
163184
args,
@@ -178,6 +199,12 @@ export class DBTClient implements Disposable {
178199
});
179200
}
180201

202+
private raiseDBTVersionCouldNotBeDeterminedEvent(): void {
203+
this._onDBTInstallationFound.fire({
204+
installed: true
205+
});
206+
}
207+
181208
private raiseDBTVersionEvent(
182209
installedVersion: string,
183210
latestVersion: string

src/statusbar/versionStatusBar.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ export class VersionStatusBar implements Disposable {
4343
return;
4444
}
4545
if (!event.upToDate) {
46-
this.showTextInStatusBar(
47-
`$(error) dbt ${event.installedVersion!} is not up to date`,
48-
{ title: "Update dbt", command: "dbtPowerUser.updateDBT" }
49-
);
46+
if(event.installedVersion !== undefined) {
47+
this.showTextInStatusBar(
48+
`$(error) dbt ${event.installedVersion} is not up to date`,
49+
{ title: "Update dbt", command: "dbtPowerUser.updateDBT" }
50+
);
51+
} else {
52+
this.showTextInStatusBar(
53+
`$(check) dbt`
54+
);
55+
}
5056
return;
5157
}
5258
this.showTextInStatusBar(`$(check) dbt ${event.installedVersion}`);

0 commit comments

Comments
 (0)