Skip to content

Commit 8f45afa

Browse files
feat(firebolt): Automatically start the engine after connection (#9001)
* automatically start the engine after connection * add tests * fix linter * start engine in the end of the test
1 parent 82ba01a commit 8f45afa

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

packages/cubejs-firebolt-driver/src/FireboltDriver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
7777
testConnectionTimeout?: number,
7878
} = {},
7979
) {
80-
super(config);
80+
// Set connection timeout to 2 minutes to allow the engine to start if it's stopped
81+
super({ testConnectionTimeout: 120000, ...config });
8182

8283
const dataSource =
8384
config.dataSource ||
@@ -122,6 +123,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
122123
private async initConnection() {
123124
try {
124125
const connection = await this.firebolt.connect(this.config.connection);
126+
await this.ensureEngineRunning();
125127
return connection;
126128
} catch (e) {
127129
this.connection = null;
@@ -174,7 +176,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
174176
await connection.testConnection();
175177
} catch (error) {
176178
console.log(error);
177-
throw new Error('Unable to connect');
179+
throw error;
178180
}
179181
}
180182

packages/cubejs-firebolt-driver/test/autostart.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import {assertDataSource, getEnv} from '@cubejs-backend/shared';
12
import { DriverTests } from '@cubejs-backend/testing-shared';
23

34
import { FireboltDriver } from '../src';
5+
import { Firebolt } from 'firebolt-sdk';
6+
import { version } from 'firebolt-sdk/package.json';
47

58
describe('FireboltDriver autostart', () => {
69
let tests: DriverTests;
@@ -30,4 +33,38 @@ describe('FireboltDriver autostart', () => {
3033
expect(driver.ensureEngineRunning).toHaveBeenCalled();
3134
}
3235
});
36+
test('starts the engine after connection', async () => {
37+
const dataSource = assertDataSource('default');
38+
39+
const username = getEnv('dbUser', { dataSource });
40+
const auth = username.includes('@')
41+
? { username, password: getEnv('dbPass', { dataSource }) }
42+
: { client_id: username, client_secret: getEnv('dbPass', { dataSource }) };
43+
const engineName = getEnv('fireboltEngineName', { dataSource });
44+
const firebolt = Firebolt({
45+
apiEndpoint: getEnv('fireboltApiEndpoint', { dataSource }) || 'api.app.firebolt.io',
46+
})
47+
await firebolt.connect({
48+
auth,
49+
database: getEnv('dbName', { dataSource }),
50+
account: getEnv('fireboltAccount', { dataSource }),
51+
engineEndpoint: getEnv('fireboltEngineEndpoint', { dataSource }),
52+
additionalParameters: {
53+
userClients: [{
54+
name: 'CubeDev+Cube',
55+
version
56+
}]
57+
},
58+
});
59+
60+
const engine = await firebolt.resourceManager.engine.getByName(engineName);
61+
try {
62+
await engine.stop();
63+
64+
driver = new FireboltDriver({});
65+
await driver.testConnection();
66+
} finally {
67+
await engine.start();
68+
}
69+
});
3370
});

0 commit comments

Comments
 (0)