This commit is contained in:
aozhiwei 2023-07-05 20:03:26 +08:00
parent e36f23ec19
commit 3cf7b36e8c

View File

@ -39,10 +39,10 @@ class PullDbEvent extends BaseService {
this.conn = conn;
this.net = net;
this.event = event;
this.lastIdx = BigInt(0);
this.eventConf = this.event['eventConf'];
this.progInfo = this.event['progressInfo'];
this.contractAddress = this.net.getContractAddressByName(this.getContractName());
this.lastIdx = await this.getLastIdx();
this.progInfo['lastIdx'] = this.lastIdx.toString();
await this.start();
}
@ -129,6 +129,29 @@ class PullDbEvent extends BaseService {
return this.eventConf['table_name'];
}
async getLastIdx() {
const logHead = this.getInstanceName() + ' getLastIdx: ';
while (true) {
const {err, row} = await this.conn.ormSelectOne(
't_dbpull_last_idx',
[
['net_id', this.getNetId()],
['contract_address', this.getContractAddress()],
['event_name', this.getEventName()],
]
);
if (err) {
log.error(logHead + err);
await utils.sleep(5000 + utils.randRange(500, 1500));
continue;
}
if (row) {
return BigInt(row['last_idx']);
}
}
return BigInt(0);
}
async saveLastIdx(lastIdx) {
const logHead = this.getInstanceName() + ' saveLastIdx: ';
while (true) {