1
This commit is contained in:
parent
e70f0a5086
commit
3b037c7c0b
@ -21,9 +21,20 @@ class BaseEventProcess {
|
|||||||
|
|
||||||
async safeRelease() {
|
async safeRelease() {
|
||||||
try {
|
try {
|
||||||
|
if (this.bcEventConn) {
|
||||||
|
this.bcEventConn.release();
|
||||||
|
this.bcEventConn = null;
|
||||||
|
}
|
||||||
|
if (this.bcNftConn) {
|
||||||
|
this.bcNftConn.release();
|
||||||
|
this.bcNftConn = null;
|
||||||
|
}
|
||||||
|
if (this.gameConn) {
|
||||||
|
this.gameConn.release();
|
||||||
|
this.gameConn = null;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
utils.safeDumpErrStack(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +83,8 @@ class BaseEventProcess {
|
|||||||
async updateEventDb(fields) {
|
async updateEventDb(fields) {
|
||||||
const logHead = this.genLogHead('updateEventDb');
|
const logHead = this.genLogHead('updateEventDb');
|
||||||
while (true) {
|
while (true) {
|
||||||
const {err} = await this.conn.update(
|
const {err} = await this.bcEventConn(
|
||||||
|
'update',
|
||||||
this.eventProc.getTableName(),
|
this.eventProc.getTableName(),
|
||||||
[
|
[
|
||||||
['idx', this.getEventDb['idx']],
|
['idx', this.getEventDb['idx']],
|
||||||
@ -109,8 +121,8 @@ class BaseEventProcess {
|
|||||||
async add721NftRefresh(netId, contractAddress, contractName, tokenId) {
|
async add721NftRefresh(netId, contractAddress, contractName, tokenId) {
|
||||||
while (true) {
|
while (true) {
|
||||||
const nowTime = utils.getUtcTime();
|
const nowTime = utils.getUtcTime();
|
||||||
const {err} = await this.conn.upsert
|
const {err} = await this.bcEventConn(
|
||||||
(
|
'upsert',
|
||||||
't_erc721_refresh',
|
't_erc721_refresh',
|
||||||
[
|
[
|
||||||
['net_id', netId],
|
['net_id', netId],
|
||||||
@ -142,20 +154,53 @@ class BaseEventProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async bcEventDbConn(method, ...args) {
|
async bcEventDbConn(method, ...args) {
|
||||||
const conn = await this.getMarketDb();
|
if (!this.bcEventConn) {
|
||||||
|
const {err, conn} = await app.getDbConn(constant.BCEVENTDB_NAME);
|
||||||
|
if (err) {
|
||||||
|
return {
|
||||||
|
'err': err,
|
||||||
|
'row': null,
|
||||||
|
'rows': null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.bcEventConn = conn;
|
||||||
|
}
|
||||||
|
return await this.internalDbConn(this.bcEventConn, method, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async bcNftDbConn(method, ...args) {
|
||||||
|
if (!this.bcNftConn) {
|
||||||
|
const {err, conn} = await app.getDbConn(constant.BCNFTDB_NAME);
|
||||||
|
if (err) {
|
||||||
|
return {
|
||||||
|
'err': err,
|
||||||
|
'row': null,
|
||||||
|
'rows': null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.bcNftConn = conn;
|
||||||
|
}
|
||||||
|
return await this.internalDbConn(this.bcNftConn, method, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async gameDbConn(method, ...args) {
|
||||||
|
if (!this.gameConn) {
|
||||||
|
const {err, conn} = await app.getDbConn(constant.BCNFTDB_NAME);
|
||||||
|
if (err) {
|
||||||
|
return {
|
||||||
|
'err': err,
|
||||||
|
'row': null,
|
||||||
|
'rows': null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.gameConn = conn;
|
||||||
|
}
|
||||||
|
return await this.internalDbConn(this.gameConn, method, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async internalDbConn(conn, method, ...args) {
|
||||||
const ret = await conn[method](...args);
|
const ret = await conn[method](...args);
|
||||||
if (ret.err){
|
return ret;
|
||||||
this.throwError(500, 'internal error');
|
|
||||||
log.error(ret.err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (utils.hasKey(ret, 'row')) {
|
|
||||||
return ret['row'];
|
|
||||||
} else if (utils.hasKey(ret, 'rows')) {
|
|
||||||
return ret['rows'];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user