rearanged startup process
This commit is contained in:
parent
65f90270e6
commit
8b24b2f0cb
1 changed files with 29 additions and 17 deletions
46
index.js
46
index.js
|
@ -97,42 +97,54 @@ function Server () {
|
||||||
/* create server */
|
/* create server */
|
||||||
this.server = http.Server(this.app);
|
this.server = http.Server(this.app);
|
||||||
};
|
};
|
||||||
|
this.startServerListening = () => {
|
||||||
|
logger.info(`Starting server on ${PORT}...`);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.server.listen(PORT, () => {
|
||||||
|
logger.info(`Server is listening on PORT ${PORT}`);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
};
|
||||||
this.syncDatabase = () => {
|
this.syncDatabase = () => {
|
||||||
|
logger.info(`Syncing database...`);
|
||||||
return createDatabaseIfNotExists()
|
return createDatabaseIfNotExists()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
db.sequelize.sync();
|
db.sequelize.sync();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
this.performChecksAndUpdates = () => {
|
||||||
|
logger.info(`Getting wallet balance and updating resources`);
|
||||||
|
return Promise.all([
|
||||||
|
getWalletBalance(),
|
||||||
|
[],
|
||||||
|
db.Tor.refreshTable(),
|
||||||
|
])
|
||||||
|
.then(([walletBalance, updatedBlockedList, updatedTorList]) => {
|
||||||
|
logger.info('Starting LBC balance:', walletBalance);
|
||||||
|
logger.info('Blocked list length:', updatedBlockedList.length);
|
||||||
|
logger.info('Tor list length:', updatedTorList.length);
|
||||||
|
})
|
||||||
|
};
|
||||||
this.start = () => {
|
this.start = () => {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
this.createApp();
|
this.createApp();
|
||||||
this.createServer();
|
this.createServer();
|
||||||
logger.info(`Syncing database...`);
|
|
||||||
this.syncDatabase()
|
this.syncDatabase()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger.info(`Starting server on ${PORT}...`);
|
return this.startServerListening();
|
||||||
return this.server.listen(PORT, () => {
|
|
||||||
logger.info(`Server is listening on PORT ${PORT}`);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger.info(`Getting starting balance`);
|
return this.performChecksAndUpdates();
|
||||||
logger.info(`Updating blocked list`);
|
|
||||||
logger.info(`Updating tor node list`);
|
|
||||||
Promise.all([
|
|
||||||
getWalletBalance(),
|
|
||||||
[],
|
|
||||||
db.Tor.refreshTable(),
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
.then(([walletBalance, updatedBlockedList, updatedTorList]) => {
|
.then(() => {
|
||||||
logger.info('Starting LBC balance:', walletBalance);
|
logger.info('Spee.ch startup is complete.');
|
||||||
logger.info('Blocked list length:', updatedBlockedList.length);
|
|
||||||
logger.info('Tor list length:', updatedTorList.length);
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.code === 'ECONNREFUSED') {
|
if (error.code === 'ECONNREFUSED') {
|
||||||
return logger.error('Connection refused. The daemon may not be running.')
|
return logger.error('Connection refused. The daemon may not be running.')
|
||||||
|
} else if (error.code === 'EADDRINUSE') {
|
||||||
|
return logger.error('Server could not start listening. The port is already in use.');
|
||||||
} else if (error.message) {
|
} else if (error.message) {
|
||||||
logger.error(error.message);
|
logger.error(error.message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue