-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwait-mysql.ts
More file actions
44 lines (37 loc) · 853 Bytes
/
wait-mysql.ts
File metadata and controls
44 lines (37 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'reflect-metadata';
import { Connection, createConnection } from 'typeorm';
const sleep = async (ms: number) =>
new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
const createDbConnection = async () => {
return createConnection({
type: 'mysql',
host: '127.0.0.1',
port: 3306,
username: 'docker',
password: 'docker',
database: 'graphql_clean_dev_auth_local',
synchronize: false,
logging: false,
});
};
const waitConnection = async () => {
let count = 30;
let dbConnection: Connection | undefined;
while (count > 0) {
--count;
try {
dbConnection = await createDbConnection();
} catch (e) {
await sleep(1000);
continue;
}
if (dbConnection?.isConnected) break;
await sleep(1000);
}
process.exit();
};
waitConnection();