70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
const app = require('j7/app');
|
|
const utils = require('j7/utils');
|
|
const bcutils = require('j7/bcutils');
|
|
const log = require('j7/log');
|
|
const constant = require('common/constant');
|
|
const BaseService = require('./baseservice');
|
|
|
|
const LIMIT_COUNT = 100;
|
|
|
|
class Erc721Refresher extends BaseService {
|
|
|
|
async init(bc, net, refresher) {
|
|
const {err, conn} = await app.getDbConn(constant.BCEVENTDB_NAME);
|
|
this.conn = conn;
|
|
this.bc = bc;
|
|
this.net = net;
|
|
this.refresher = refresher;
|
|
this.conf = this.refresher['conf'];
|
|
this.progInfo = this.refresher['progressInfo'];
|
|
await this.start();
|
|
}
|
|
|
|
async start() {
|
|
while (true) {
|
|
await this.pullEvent();
|
|
await utils.sleep(2000 + utils.randRange(500, 1500));
|
|
}
|
|
}
|
|
|
|
async pullEvent() {
|
|
const logHead = this.genLogHead('pullEvent ');
|
|
try {
|
|
const {err, rows} = await this.conn.execQuery(
|
|
'SELECT * FROM t_erc721_refresh WHERE ' +
|
|
'AND net_id = ? AND contract_address = ? status = 0 ' +
|
|
'LIMIT ' + LIMIT_COUNT,
|
|
[
|
|
this.getNetId(),
|
|
this.getContractAddress()
|
|
]);
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
} catch (err) {
|
|
log.error(logHead + err);
|
|
await utils.sleep(5000 + utils.randRange(1000, 3000));
|
|
}
|
|
}
|
|
|
|
getNetId() {
|
|
return this.net['net_id'];
|
|
}
|
|
|
|
getContractAddress() {
|
|
return this.bc.getContractAddressByName(this.getContractName());
|
|
}
|
|
|
|
getContractName() {
|
|
return this.conf['contract_name'];
|
|
}
|
|
|
|
genLogHead(msg) {
|
|
const head = this.getNetId() + '.' + this.getContractName() + ' erc721 refresher ' + msg;
|
|
return head;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Erc721Refresher;
|