diff --git a/api/api.js b/api/api.js index 9ad9c5ff..fc8339d0 100644 --- a/api/api.js +++ b/api/api.js @@ -13,6 +13,7 @@ import redis from 'redis'; import WebSocket from 'ws'; import _ from 'lodash'; import './inbound-stream'; +import './uptime-crawler'; import geoip from 'geoip-lite'; import YAML from 'yaml'; import fs from 'fs'; diff --git a/api/uptime-crawler.js b/api/uptime-crawler.js index 67af23c8..45b2a23b 100644 --- a/api/uptime-crawler.js +++ b/api/uptime-crawler.js @@ -4,15 +4,19 @@ import YAML from 'yaml'; import redis from 'redis'; import {promisify} from 'util'; import {exec} from 'child_process'; +import {sync as commandExistsSync} from 'command-exists'; import config from './config'; -const SOLANA_WALLET_PATH = - process.env.SOLANA_WALLET_PATH || '../solana/target/debug'; const FULLNODE_URL = process.env.FULLNODE_URL || 'http://localhost:8899'; const REFRESH_INTERVAL = 10 * 60 * 1000; // 10min +if (!commandExistsSync('solana-wallet')) { + throw 'solana-wallet command not found!'; +} + + function getClient() { let props = config.redis.path ? {path: config.redis.path} @@ -29,7 +33,7 @@ function getVoteAccountUptime(x) { const p = new Promise((resolve, reject) => { exec( - `${SOLANA_WALLET_PATH}/solana-wallet -u ${FULLNODE_URL} show-vote-account ${x.votePubkey}`, + `solana-wallet -u ${FULLNODE_URL} show-vote-account ${x.votePubkey}`, (err, stdout, stderr) => { const t2 = new Date().getTime(); @@ -75,6 +79,7 @@ function getVoteAccountUptime(x) { } async function refreshUptime() { + console.log('uptime updater: updating...'); const connection = new solanaWeb3.Connection(FULLNODE_URL); let voting = await connection.getEpochVoteAccounts(); @@ -84,6 +89,7 @@ async function refreshUptime() { Promise.all(allTasks).then(async results => { await setAsync('!uptime', JSON.stringify(results)); + console.log('uptime updater: updated successfully.'); }); } diff --git a/package.json b/package.json index c767611c..c1051863 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "babel-plugin-transform-runtime": "^6.23.0", "base-58": "^0.0.1", "classnames": "^2.2.6", + "command-exists": "^1.2.8", "copy-to-clipboard": "^3.2.0", "cors": "^2.8.5", "date-fns": "^1.30.1", @@ -99,7 +100,6 @@ "prepack": "set -ex; npm run lint; npm run build", "pretty": "prettier --write '{,{api,proxy,src}/**/}*.js{,x}'", "re": "semantic-release --repository-url git@github.com:solana-labs/blockexplorer.git", - "start:uptime-crawler": "set -ex; redis-cli ping; babel-node --presets env api/uptime-crawler.js", "start:api": "set -ex; redis-cli ping; babel-node --presets env api/api.js", "start:proxy": "babel-node --presets env proxy", "start:ui": "react-app-rewired start", diff --git a/yarn.lock b/yarn.lock index b786959d..238dea2f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4604,6 +4604,11 @@ comma-separated-tokens@^1.0.0: dependencies: trim "0.0.1" +command-exists@^1.2.8: + version "1.2.8" + resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291" + integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw== + commander@2, commander@^2.11.0, commander@^2.12.2, commander@^2.20.0: version "2.20.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"