1
This commit is contained in:
parent
6b95277886
commit
0484a09172
@ -49,7 +49,7 @@ class DbEventProcess extends BaseService {
|
|||||||
this.progInfo = this.event['progressInfo'];
|
this.progInfo = this.event['progressInfo'];
|
||||||
this.contractAddress = this.net.getContractAddressByName(this.getContractName());
|
this.contractAddress = this.net.getContractAddressByName(this.getContractName());
|
||||||
this.lastIdx = await this.getLastIdx();
|
this.lastIdx = await this.getLastIdx();
|
||||||
this.progInfo['lastIdx'] = this.lastIdx.toString();
|
this.progInfo['proclastIdx'] = this.lastIdx.toString();
|
||||||
await this.start();
|
await this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,46 @@ class DbEventProcess extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async pullEvent() {
|
async pullEvent() {
|
||||||
const logHead = this.getInstanceName() + ' pullEvent: ';
|
const logHead = this.getInstanceName() + ' pullDbEvent: ';
|
||||||
|
const tableName = this.getTableName();
|
||||||
|
try {
|
||||||
|
const startIdx = this.getStartIdx();
|
||||||
|
const endIdx = this.getEndIdx();
|
||||||
|
++this.progInfo['procPullCount'];
|
||||||
|
if (startIdx >= endIdx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const {err, rows} = await this.conn.execQuery(
|
||||||
|
'SELECT * FROM ${tableName} WHERE `idx` > ? AND `idx` <= ? ' +
|
||||||
|
'AND net_id = ? AND event_name = ? AND contract_address = ? ' +
|
||||||
|
'LIMIT ' + LIMIT_COUNT,
|
||||||
|
[
|
||||||
|
startIdx.toString(),
|
||||||
|
endIdx.toString(),
|
||||||
|
this.getNetId(),
|
||||||
|
this.getEventName(),
|
||||||
|
this.getContractAddress()
|
||||||
|
]);
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (rows.length > 0) {
|
||||||
|
await utils.serial(
|
||||||
|
rows,
|
||||||
|
async (row) => {
|
||||||
|
await this.saveToDb(row);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.progInfo['procEventCount'] += rows.length;
|
||||||
|
} else {
|
||||||
|
this.lastIdx = endIdx;
|
||||||
|
}
|
||||||
|
this.progInfo['procLastIdx'] = this.lastIdx.toString();
|
||||||
|
await this.saveLastIdx(this.lastIdx);
|
||||||
|
} catch (err) {
|
||||||
|
log.error(logHead + err);
|
||||||
|
await utils.sleep(5000 + utils.randRange(1000, 3000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getStartIdx() {
|
getStartIdx() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user