This commit is contained in:
aozhiwei 2023-07-03 18:05:35 +08:00
parent 9c0b633dc9
commit ff55e15735

View File

@ -26,7 +26,7 @@ class PullBcEvent extends BaseService {
} }
async pullEvent() { async pullEvent() {
const logClass = this.getInstanceName() + ' pullEvent:'; const logHead = this.getInstanceName() + ' pullEvent:';
while (true) { while (true) {
await this.bc.lockQuery(); await this.bc.lockQuery();
try { try {
@ -46,7 +46,7 @@ class PullBcEvent extends BaseService {
++this.progInfo['pullCount']; ++this.progInfo['pullCount'];
return; return;
} catch (err) { } catch (err) {
log.error(logClass + err); log.error(logHead + err);
await utils.sleep(1000 + utils.randRange(10, 2000)); await utils.sleep(1000 + utils.randRange(10, 2000));
} finally { } finally {
await this.bc.unlockQuery(); await this.bc.unlockQuery();
@ -78,7 +78,7 @@ class PullBcEvent extends BaseService {
} }
async getFromBlock() { async getFromBlock() {
const logClass = this.getInstanceName() + ' getFromBlock:'; const logHead = this.getInstanceName() + ' getFromBlock:';
const firstBlockNumber = this.getInitBlock(); const firstBlockNumber = this.getInitBlock();
while (this.lastBlockNumber < 1) { while (this.lastBlockNumber < 1) {
try { try {
@ -97,7 +97,7 @@ class PullBcEvent extends BaseService {
this.lastBlockNumber = firstBlockNumber; this.lastBlockNumber = firstBlockNumber;
} }
} }
console.log(logClass, this.lastBlockNumber, this.bc.getCurrBlockNumber()); console.log(logHead, this.lastBlockNumber, this.bc.getCurrBlockNumber());
while (this.lastBlockNumber + 8 > this.bc.getCurrBlockNumber()) { while (this.lastBlockNumber + 8 > this.bc.getCurrBlockNumber()) {
await utils.sleep(1000 + utils.randRange(500, 1500)); await utils.sleep(1000 + utils.randRange(500, 1500));
} }
@ -125,7 +125,7 @@ class PullBcEvent extends BaseService {
} }
async saveLastBlockNumber(blockNumber) { async saveLastBlockNumber(blockNumber) {
const logClass = 'event_process.saveLastBlockNumber'; const logHead = 'event_process.saveLastBlockNumber';
while (true) { while (true) {
const {err} = await this.conn.upsert( const {err} = await this.conn.upsert(
't_parameter', 't_parameter',
@ -143,14 +143,14 @@ class PullBcEvent extends BaseService {
if (!err) { if (!err) {
break; break;
} }
log.error(logClass + err); log.error(logHead + err);
await utils.sleep(5000 + utils.randRange(500, 1500)); await utils.sleep(5000 + utils.randRange(500, 1500));
} }
this.lastBlockNumber = blockNumber; this.lastBlockNumber = blockNumber;
} }
async saveToDb(event) { async saveToDb(event) {
const logClass = 'event_process.saveToDb'; const logHead = 'event_process.saveToDb';
while (true) { while (true) {
const nowTime = utils.getUtcTime(); const nowTime = utils.getUtcTime();
const returnValues = event['returnValues']; const returnValues = event['returnValues'];
@ -179,7 +179,7 @@ class PullBcEvent extends BaseService {
if (!err) { if (!err) {
break; break;
} }
log.error(logClass + err); log.error(logHead + err);
await utils.sleep(5000 + utils.randRange(500, 1500)); await utils.sleep(5000 + utils.randRange(500, 1500));
} }
} }