1
This commit is contained in:
parent
11d5213607
commit
11de81c34f
@ -37,7 +37,6 @@ class LuckyBox extends basewrap.BaseWrap {
|
|||||||
}
|
}
|
||||||
const data = LuckyBox.idTypeHash[key];
|
const data = LuckyBox.idTypeHash[key];
|
||||||
assert(data['total_space'] > 0);
|
assert(data['total_space'] > 0);
|
||||||
console.log(data);
|
|
||||||
const rand = utils.randRange(0, data['total_space'] - 1);
|
const rand = utils.randRange(0, data['total_space'] - 1);
|
||||||
for (let i in data['items']) {
|
for (let i in data['items']) {
|
||||||
const item = data['items'][i];
|
const item = data['items'][i];
|
||||||
@ -45,7 +44,6 @@ class LuckyBox extends basewrap.BaseWrap {
|
|||||||
return item['meta']['item_id'];
|
return item['meta']['item_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(22222, rand);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,35 @@ class EventCenter extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initEventProcess() {
|
async initEventProcess() {
|
||||||
|
const initInstance = (instance) => {
|
||||||
|
instance['pullCount'] = 0;
|
||||||
|
instance['eventCount'] = 0;
|
||||||
|
instance['fromBlock'] = 0;
|
||||||
|
instance['toBlock'] = 0;
|
||||||
|
instance['currBlock'] = 0;
|
||||||
|
};
|
||||||
|
const allInstances = [];
|
||||||
|
{
|
||||||
|
this.instances.forEach((item) => {
|
||||||
|
allInstances.push(item);
|
||||||
|
});
|
||||||
|
allInstances.push(this.boxInstance);
|
||||||
|
allInstances.forEach((item) => {
|
||||||
|
initInstance(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
const outputLog = async () => {
|
||||||
|
while (true) {
|
||||||
|
log.info(++count + '-------------------------------------------------------------');
|
||||||
|
allInstances.forEach((item) => {
|
||||||
|
log.info(utils.jsonEncode(item));
|
||||||
|
});
|
||||||
|
await utils.sleep(1000 * 10);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setTimeout(outputLog, 1000 * 3);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
this.instances.forEach(async (item) => {
|
this.instances.forEach(async (item) => {
|
||||||
factory.create('EventProcess', null)
|
factory.create('EventProcess', null)
|
||||||
|
@ -26,17 +26,8 @@ class EventProcess extends BaseService {
|
|||||||
const logClass = this.getInstanceName() + ' pullEvent:';
|
const logClass = this.getInstanceName() + ' pullEvent:';
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
console.log('pullEvent1',
|
|
||||||
utils.jsonEncode(this.instance));
|
|
||||||
const fromBlock = await this.getFromBlock();
|
const fromBlock = await this.getFromBlock();
|
||||||
console.log('pullEvent2',
|
|
||||||
utils.jsonEncode(this.instance));
|
|
||||||
const toBlock = await this.calcToBlock(fromBlock);
|
const toBlock = await this.calcToBlock(fromBlock);
|
||||||
console.log('pullEvent',
|
|
||||||
fromBlock,
|
|
||||||
toBlock,
|
|
||||||
bc.getCurrBlockNumber(),
|
|
||||||
utils.jsonEncode(this.instance));
|
|
||||||
if (toBlock >= fromBlock) {
|
if (toBlock >= fromBlock) {
|
||||||
const events = await bc[this.getInstanceName()].getPastEvents(
|
const events = await bc[this.getInstanceName()].getPastEvents(
|
||||||
this.instance['eventName'],
|
this.instance['eventName'],
|
||||||
@ -45,10 +36,17 @@ class EventProcess extends BaseService {
|
|||||||
toBlock: toBlock,
|
toBlock: toBlock,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
this.instance['fromBlock'] = fromBlock;
|
||||||
|
this.instance['toBlock'] = toBlock;
|
||||||
|
this.instance['currBlock'] = bc.getCurrBlockNumber();
|
||||||
|
this.instance['eventCount'] += events.length;
|
||||||
|
if (events.length > 0) {
|
||||||
console.log(events);
|
console.log(events);
|
||||||
|
}
|
||||||
await this.processEvents(events, toBlock);
|
await this.processEvents(events, toBlock);
|
||||||
await this.saveLastBlockNumber(toBlock);
|
await this.saveLastBlockNumber(toBlock);
|
||||||
}
|
}
|
||||||
|
++this.instance['pullCount'];
|
||||||
return;
|
return;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(logClass + err);
|
log.error(logClass + err);
|
||||||
@ -91,16 +89,12 @@ class EventProcess extends BaseService {
|
|||||||
this.lastBlockNumber = firstBlockNumber;
|
this.lastBlockNumber = firstBlockNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('getFromBlock',
|
|
||||||
this.lastBlockNumber,
|
|
||||||
bc.getCurrBlockNumber(),
|
|
||||||
utils.jsonEncode(this.instance));
|
|
||||||
while (this.lastBlockNumber + 8 > bc.getCurrBlockNumber()) {
|
while (this.lastBlockNumber + 8 > bc.getCurrBlockNumber()) {
|
||||||
await utils.sleep(1000 + utils.randRange(500, 1500));
|
await utils.sleep(1000 + utils.randRange(500, 1500));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
log.log(err);
|
||||||
}
|
}
|
||||||
await utils.sleep(5000 + utils.randRange(500, 1500));
|
await utils.sleep(5000 + utils.randRange(500, 1500));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user