57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
const utils = require("./utils");
|
|
const log = require("./log");
|
|
const db = require("./db");
|
|
const dbhelper = require("./dbhelper");
|
|
const bchelper = require("./bchelper");
|
|
const present = require("./present");
|
|
|
|
const LIMIT_COUNT = 100;
|
|
|
|
class PresentMgr {
|
|
|
|
constructor() {
|
|
this.lastIdx = 0;
|
|
}
|
|
|
|
init() {
|
|
setTimeout(this.start.bind(this), 1000 * 3);
|
|
}
|
|
|
|
async start() {
|
|
let maxIdx = 0;
|
|
while (true) {
|
|
{
|
|
const {err, rows} = await db.execQuery(
|
|
'SELECT * FROM t_mint WHERE `idx` > ? AND `ignore` = 0 AND ' +
|
|
'done = 0 AND suspend = 0 LIMIT ' + LIMIT_COUNT,
|
|
[this.lastIdx]);
|
|
if (!err) {
|
|
for (let i in rows) {
|
|
const row = rows[i];
|
|
const obj = new present.Present(row);
|
|
obj.start();
|
|
if (row['idx'] > this.lastIdx) {
|
|
this.lastIdx = row['idx'];
|
|
}
|
|
await utils.sleep(5000 + utils.randRange(500, 1000));
|
|
}
|
|
if (rows.length < 1 && this.lastIdx + LIMIT_COUNT < maxIdx) {
|
|
this.lastIdx += LIMIT_COUNT;
|
|
}
|
|
}
|
|
}
|
|
{
|
|
const {err, row} = await db.execQueryOne(
|
|
'SELECT max(idx) max_idx FROM t_mint', []);
|
|
if (!err && row['max_idx'] != null) {
|
|
maxIdx = row['max_idx'];
|
|
}
|
|
}
|
|
await utils.sleep(1500 + utils.randRange(500, 1500));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = new PresentMgr();
|