This commit is contained in:
aozhiwei 2023-07-04 21:29:47 +08:00
parent e5806b12d2
commit e5ac1163c4
4 changed files with 60 additions and 1 deletions

View File

@ -0,0 +1,50 @@
const app = require('j7/app');
const utils = require('j7/utils');
const bcutils = require('j7/bcutils');
const log = require('j7/log');
const BaseService = require('./baseservice');
class DbEventProcess extends BaseService {
async init(net, event) {
const {err, conn} = await app.getDbConn('BcEventDb0');
this.conn = conn;
this.net = net;
this.event = event;
this.lastIdx = BigInt(0);
this.eventConf = this.event['eventConf'];
this.progInfo = this.event['progressInfo'];
await this.start();
}
async start() {
while (true) {
await this.pullEvent();
await utils.sleep(500 + utils.randRange(500, 1500));
}
}
async pullEvent() {
const logHead = this.getInstanceName() + ' pullEvent: ';
}
getEventName() {
return this.eventConf['event_name'];
}
getContractAddress() {
//return this.bc.getContractAddressByName(this.getContractName());
}
getContractName() {
return this.eventConf['contract_name'];
}
getInstanceName() {
const instName = this.getNetId() + '.' + this.getContractName() + '.' + this.getEventName();
return instName;
}
}
module.exports = DbEventProcess;

View File

@ -23,7 +23,8 @@ async function addSingle(clsName, modName) {
async function init() {
await add("BlockChain", 'blockchain');
add(['PullDbEvent'], 'pull_dbevent');
await add(['PullDbEvent'], 'pull_dbevent');
await add(['DbEventProcess'], 'dbevent_process');
}
function create(name, session = null) {

View File

@ -11,6 +11,7 @@ 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'];
await this.start();

View File

@ -43,6 +43,13 @@ class DbSpider extends BaseTask {
return pullDbEventService;
}
createDbEventProcessService(net, event) {
const DbEventProcessService = serviceFactory.create('DbEventProcess');
event['DbEventProcessService'] = DbEventProcessService;
DbEventProcessService.init(net, event);
return DbEventProcessService;
}
async outputProgressInfo(net, events) {
let count = 0;
while (true) {