From 8118d5b196061c761d8a5a8d5ecb8408805a9b70 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 17 May 2018 18:11:22 -0700 Subject: [PATCH] added check for lbrynet via startup wallet balance check --- index.js | 14 ++++++++++++-- server/lbrynet/index.js | 16 ++++++++++++++++ server/models/utils/createDatabaseIfNotExists.js | 3 +-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a812a220..32fd784d 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ const mysqlConfig = require('./config/mysqlConfig.js'); const siteConfig = require('./config/siteConfig.js'); const slackConfig = require('./config/slackConfig.js'); const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js'); +const { getWalletBalance } = require('./server/lbrynet'); function Server () { this.configureLogger = loggerConfig.update; @@ -83,6 +84,10 @@ function Server () { const PORT = siteConfig.details.port; // sync sequelize createDatabaseIfNotExists() + getWalletBalance() + .then(balance => { + logger.info('starting LBC balance:', balance); + }) .then(() => { db.sequelize.sync() }) @@ -92,8 +97,13 @@ function Server () { logger.info(`Server is listening on PORT ${PORT}`); }); }) - .catch((error) => { - logger.error(`Startup Error:`, error); + .catch(error => { + if (error.code === 'ECONNREFUSED') { + return logger.error('Connection refused. The daemon may not be running.') + } else if (error.message) { + logger.error(error.message); + } + logger.error(error); }); }; }; diff --git a/server/lbrynet/index.js b/server/lbrynet/index.js index c8ea72a1..90a45875 100644 --- a/server/lbrynet/index.js +++ b/server/lbrynet/index.js @@ -125,4 +125,20 @@ module.exports = { }); }); }, + getWalletBalance () { + const gaStartTime = Date.now(); + return new Promise((resolve, reject) => { + axios + .post(lbrynetUri, { + method: 'wallet_balance', + }) + .then(response => { + sendGATimingEvent('lbrynet', 'getWalletBalance', 'SETTINGS_GET', gaStartTime, Date.now()); + handleLbrynetResponse(response, resolve, reject); + }) + .catch(error => { + reject(error); + }); + }); + }, }; diff --git a/server/models/utils/createDatabaseIfNotExists.js b/server/models/utils/createDatabaseIfNotExists.js index d8ab0e02..4a717067 100644 --- a/server/models/utils/createDatabaseIfNotExists.js +++ b/server/models/utils/createDatabaseIfNotExists.js @@ -4,10 +4,9 @@ const createDatabaseIfNotExists = () => { const {database, username, password} = require('../../../config/mysqlConfig.js'); const sequelize = new Sequelize('', username, password, { dialect : 'mysql', - logging : true, + logging : false, operatorsAliases: false, }); - console.log('username:', username, 'password:', password); return new Promise((resolve, reject) => { sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`) .then(() => {