aozhiwei 175fd16c0c 1
2022-04-17 00:12:23 +08:00

55 lines
1.3 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");
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_present WHERE `idx` > ? AND `ignore` = 0 AND ' +
'done = 0 AND suspend = 0 LIMIT 100',
[this.lastIdx]);
if (!err) {
for (let i in rows) {
const row = rows[i];
const obj = new present.Present(row);
await obj.start();
if (row['idx'] > this.lastIdx) {
this.lastIdx = row['idx'];
}
await utils.sleep(500 + utils.randRange(500, 1000));
}
if (this.lastIdx < maxIdx + 99) {
this.lastIdx = maxIdx;
}
}
}
{
const {err, row} = await db.execQueryOne(
'SELECT max(idx) max_idx FROM t_present', []);
if (!err) {
maxIdx = row['max_idx'];
}
}
await utils.sleep(1500 + utils.randRange(500, 1500));
}
}
}
module.exports = new PresentMgr();