forked from tot-ra/graphql-schema-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema-registry.js
53 lines (42 loc) · 1.31 KB
/
schema-registry.js
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
45
46
47
48
49
50
51
52
53
require('dotenv').config();
const logger = require('./app/logger');
const CustomSqlMigrationSource = require('./app/database/sql-migration-source');
process.on('unhandledRejection', (error) => {
logger.error(`unhandledRejection: ${error.message}`, {
original_error: error,
});
setTimeout(() => process.exit(), 3000);
});
process.on('uncaughtException', (error) => {
logger.error(`uncaughtException: ${error.message}`, {
original_error: error,
});
setTimeout(() => process.exit(), 3000);
});
logger.info(`Starting schema-registry...`);
async function warmup() {
logger.info('Warming up');
logger.info(
`Looking for environment variable DB_EXECUTE_MIGRATIONS = ${process.env.DB_EXECUTE_MIGRATIONS}`
);
const executeMigrations = (
process.env.DB_EXECUTE_MIGRATIONS || 'true'
).trim();
logger.info(`Will execute DB migrations? ${executeMigrations}`);
try {
if (executeMigrations === 'true') {
await require('./app/database').knex.migrate.latest({
migrationSource: new CustomSqlMigrationSource('./migrations'),
disableMigrationsListValidation: true,
});
}
await require('./app').init();
logger.info('Warm up complete');
} catch (error) {
logger.error(`Service failed to warm up: ${error.message}`, {
original_error: error,
});
setTimeout(() => warmup(), 10000);
}
}
warmup();