address review comments
This commit is contained in:
parent
9934258046
commit
e7cf20eda4
2 changed files with 14 additions and 11 deletions
|
@ -6,14 +6,14 @@ import helmet from 'koa-helmet';
|
||||||
import routing from './routes/';
|
import routing from './routes/';
|
||||||
import { port } from './config';
|
import { port } from './config';
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import slack from 'node-slack';
|
import Slack from 'node-slack';
|
||||||
require('winston-daily-rotate-file');
|
require('winston-daily-rotate-file');
|
||||||
|
|
||||||
// Setup logging
|
// Setup logging
|
||||||
winston.remove(winston.transports.Console);
|
winston.remove(winston.transports.Console);
|
||||||
winston.add(winston.transports.Console, { colorize: true, timestamp: true, prettyPrint: true });
|
winston.add(winston.transports.Console, { colorize: true, timestamp: true, prettyPrint: true });
|
||||||
let slackAPIKey = process.env.SLACK_HOOK_URL;
|
const slackAPIKey = process.env.SLACK_HOOK_URL;
|
||||||
let mySlack = new slack(slackAPIKey, {});
|
const mySlack = new Slack(slackAPIKey, {});
|
||||||
// Create Koa Application
|
// Create Koa Application
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,19 @@ import fileExists from 'file-exists';
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
import {logErrorToSlack} from '../../index';
|
import {logErrorToSlack} from '../../index';
|
||||||
import mysql from 'mysql';
|
import mysql from 'mysql';
|
||||||
|
import chainqueryConfig from '../../../chainquery-config.json';
|
||||||
|
|
||||||
const elasticsearchloglevel = 'info';
|
let connection = null;
|
||||||
|
|
||||||
|
const esLogLevel = 'info';
|
||||||
const MaxClaimsToProcessPerIteration = 100000;
|
const MaxClaimsToProcessPerIteration = 100000;
|
||||||
const BatchSize = 5000;
|
const BatchSize = 5000;
|
||||||
const loggerStream = winstonStream(winston, elasticsearchloglevel);
|
const loggerStream = winstonStream(winston, esLogLevel);
|
||||||
const eclient = new elasticsearch.Client({
|
const eclient = new elasticsearch.Client({
|
||||||
host: 'http://localhost:9200',
|
host: 'http://localhost:9200',
|
||||||
|
|
||||||
log: {
|
log: {
|
||||||
level : elasticsearchloglevel,
|
level : esLogLevel,
|
||||||
type : 'stream',
|
type : 'stream',
|
||||||
stream: loggerStream,
|
stream: loggerStream,
|
||||||
},
|
},
|
||||||
|
@ -187,10 +190,7 @@ function getBlockedOutpoints () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection = null;
|
function getChainqueryConnection () {
|
||||||
const chainqueryConfig = require('../../../chainquery-config.json');
|
|
||||||
|
|
||||||
function getClaimsSince (time, lastID, MaxClaimsInCall) {
|
|
||||||
if (connection === null) {
|
if (connection === null) {
|
||||||
connection = mysql.createConnection({
|
connection = mysql.createConnection({
|
||||||
host : chainqueryConfig.host,
|
host : chainqueryConfig.host,
|
||||||
|
@ -200,12 +200,15 @@ function getClaimsSince (time, lastID, MaxClaimsInCall) {
|
||||||
});
|
});
|
||||||
connection.connect();
|
connection.connect();
|
||||||
}
|
}
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getClaimsSince (time, lastID, MaxClaimsInCall) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let query = `SELECT c.id, c.name,p.name as channel, p.claim_id as channel_id, c.bid_state,c.effective_amount,COALESCE(p.effective_amount,1) as certificate_amount,c.claim_id as claimId,c.value_as_json as value FROM claim c LEFT JOIN claim p on p.claim_id = c.publisher_id WHERE c.id >${lastID} AND c.modified_at >='${time}' ORDER BY c.id LIMIT ${MaxClaimsInCall}`;
|
let query = `SELECT c.id, c.name,p.name as channel, p.claim_id as channel_id, c.bid_state,c.effective_amount,COALESCE(p.effective_amount,1) as certificate_amount,c.claim_id as claimId,c.value_as_json as value FROM claim c LEFT JOIN claim p on p.claim_id = c.publisher_id WHERE c.id >${lastID} AND c.modified_at >='${time}' ORDER BY c.id LIMIT ${MaxClaimsInCall}`;
|
||||||
// Outputs full query to console for copy/paste into chainquery (debugging)
|
// Outputs full query to console for copy/paste into chainquery (debugging)
|
||||||
console.log(query);
|
console.log(query);
|
||||||
connection.query(query, function (err, results, fields) {
|
getChainqueryConnection().query(query, function (err, results, fields) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
logErrorToSlack('[Importer] Error getting updated claims. ' + err);
|
logErrorToSlack('[Importer] Error getting updated claims. ' + err);
|
||||||
|
|
Loading…
Reference in a new issue