Added basic status API.
Added a basic status API, will be upgraded later on.
This commit is contained in:
parent
b55d9b5619
commit
4b05a76e28
4 changed files with 26 additions and 5 deletions
server
|
@ -3,6 +3,8 @@ import winston from 'winston';
|
||||||
import winstonStream from 'winston-stream';
|
import winstonStream from 'winston-stream';
|
||||||
import { sync, getStats } from '../utils/importer';
|
import { sync, getStats } from '../utils/importer';
|
||||||
import elasticsearch from 'elasticsearch';
|
import elasticsearch from 'elasticsearch';
|
||||||
|
import rp from 'request-promise';
|
||||||
|
import pretty from 'prettysize';
|
||||||
|
|
||||||
const loggerStream = winstonStream(winston, 'info');
|
const loggerStream = winstonStream(winston, 'info');
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ class LighthouseControllers {
|
||||||
* @param {ctx} Koa Context
|
* @param {ctx} Koa Context
|
||||||
*/
|
*/
|
||||||
async info (ctx) {
|
async info (ctx) {
|
||||||
ctx.body = 'Lighthouse';
|
ctx.body = 'Lighthouse search API';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,7 +134,14 @@ class LighthouseControllers {
|
||||||
* @param {ctx} Koa Context
|
* @param {ctx} Koa Context
|
||||||
*/
|
*/
|
||||||
async status (ctx) {
|
async status (ctx) {
|
||||||
ctx.body = eclient.getStats();
|
rp('http://localhost:9200/claims/_stats')
|
||||||
|
.then(function (data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
ctx.body = {status: getStats().info, spaceUsed: pretty(data._all.total.store.size_in_bytes, true), claimsInIndex: data._all.total.indexing.index_total, totSearches: data._all.total.search.query_total};
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
ctx.body = err;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-enable no-param-reassign */
|
/* eslint-enable no-param-reassign */
|
||||||
|
|
5
server/package.json
Normal file
5
server/package.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"prettysize": "^1.1.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,7 +67,7 @@ let status = {};
|
||||||
|
|
||||||
export async function sync () {
|
export async function sync () {
|
||||||
try {
|
try {
|
||||||
status.info = 'Grabbing the claimTrie...';
|
status.info = 'gettingClaimTrie';
|
||||||
let claimTrie = await client.getClaimsInTrie().then(claimtrie => { return claimtrie }).catch(err => { throw err });
|
let claimTrie = await client.getClaimsInTrie().then(claimtrie => { return claimtrie }).catch(err => { throw err });
|
||||||
let txList = [];
|
let txList = [];
|
||||||
let latestClaimTrie = [];
|
let latestClaimTrie = [];
|
||||||
|
@ -84,7 +84,7 @@ export async function sync () {
|
||||||
let oldClaimTrie = await getJSON(path.join(appRoot.path, 'claimTrieCache.json')); // get our old claimTrieCache....
|
let oldClaimTrie = await getJSON(path.join(appRoot.path, 'claimTrieCache.json')); // get our old claimTrieCache....
|
||||||
let added = await getAddedClaims(oldClaimTrie, latestClaimTrie); // get all new that should be added
|
let added = await getAddedClaims(oldClaimTrie, latestClaimTrie); // get all new that should be added
|
||||||
let removed = await getRemovedClaims(oldClaimTrie, latestClaimTrie); // get all old that should be removed
|
let removed = await getRemovedClaims(oldClaimTrie, latestClaimTrie); // get all old that should be removed
|
||||||
status.info = 'Adding/Removing Claims, please wait...';
|
status.info = 'calculatingClaimTrie';
|
||||||
for (let claimId of added) { // for all new get their tx info and add to database
|
for (let claimId of added) { // for all new get their tx info and add to database
|
||||||
let tx = txList.find(x => x.claimId === claimId);
|
let tx = txList.find(x => x.claimId === claimId);
|
||||||
if (typeof tx !== 'undefined') {
|
if (typeof tx !== 'undefined') {
|
||||||
|
@ -116,7 +116,7 @@ export async function sync () {
|
||||||
}
|
}
|
||||||
// Done adding, update our claimTrie cache to latest and wait a bit...
|
// Done adding, update our claimTrie cache to latest and wait a bit...
|
||||||
await saveJSON(path.join(appRoot.path, 'claimTrieCache.json'), latestClaimTrie);
|
await saveJSON(path.join(appRoot.path, 'claimTrieCache.json'), latestClaimTrie);
|
||||||
status.info = 'Done updating the claimTrieCache, waiting 5 minutes before doing a recheck..';
|
status.info = 'upToDate';
|
||||||
await sleep(300000);
|
await sleep(300000);
|
||||||
sync();
|
sync();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
7
server/yarn.lock
Normal file
7
server/yarn.lock
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
prettysize@^1.1.0:
|
||||||
|
version "1.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/prettysize/-/prettysize-1.1.0.tgz#c6c52f87161ff172ea435f375f99831dd9a97bb0"
|
Loading…
Add table
Reference in a new issue