Added basic status API.

Added a basic status API, will be upgraded later on.
This commit is contained in:
Fillerino 2017-09-26 19:39:03 +02:00
parent b55d9b5619
commit 4b05a76e28
4 changed files with 26 additions and 5 deletions

View file

@ -3,6 +3,8 @@ import winston from 'winston';
import winstonStream from 'winston-stream';
import { sync, getStats } from '../utils/importer';
import elasticsearch from 'elasticsearch';
import rp from 'request-promise';
import pretty from 'prettysize';
const loggerStream = winstonStream(winston, 'info');
@ -124,7 +126,7 @@ class LighthouseControllers {
* @param {ctx} Koa Context
*/
async info (ctx) {
ctx.body = 'Lighthouse';
ctx.body = 'Lighthouse search API';
}
/**
@ -132,7 +134,14 @@ class LighthouseControllers {
* @param {ctx} Koa Context
*/
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 */

5
server/package.json Normal file
View file

@ -0,0 +1,5 @@
{
"dependencies": {
"prettysize": "^1.1.0"
}
}

View file

@ -67,7 +67,7 @@ let status = {};
export async function sync () {
try {
status.info = 'Grabbing the claimTrie...';
status.info = 'gettingClaimTrie';
let claimTrie = await client.getClaimsInTrie().then(claimtrie => { return claimtrie }).catch(err => { throw err });
let txList = [];
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 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
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
let tx = txList.find(x => x.claimId === claimId);
if (typeof tx !== 'undefined') {
@ -116,7 +116,7 @@ export async function sync () {
}
// Done adding, update our claimTrie cache to latest and wait a bit...
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);
sync();
} catch (err) {

7
server/yarn.lock Normal file
View 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"