Code refactor
This commit is contained in:
parent
5d0d68d85b
commit
2eb72ec258
|
@ -11,7 +11,7 @@
|
|||
"updaterows",
|
||||
"deleterows"
|
||||
],
|
||||
"interval": 5000,
|
||||
"flushInterval": 5000,
|
||||
"queue": "orderRecalc",
|
||||
"addQuery": "INSERT INTO `hedera`.`orderRecalc` (`orderFk`) VALUES ?",
|
||||
"includeSchema": {
|
||||
|
|
6
index.js
6
index.js
|
@ -65,7 +65,7 @@ async function main() {
|
|||
};
|
||||
|
||||
const [res] = await db.query(
|
||||
'SELECT `logName`, `position` FROM `util`.`asyncQueue` WHERE code = ?',
|
||||
'SELECT `logName`, `position` FROM `util`.`binlogQueue` WHERE code = ?',
|
||||
[config.queue]
|
||||
);
|
||||
if (res.length) {
|
||||
|
@ -77,7 +77,7 @@ async function main() {
|
|||
opts.startAtEnd = true;
|
||||
|
||||
zongji.start(opts);
|
||||
setInterval(flushQueue, config.interval);
|
||||
setInterval(flushQueue, config.flushInterval);
|
||||
console.log('Listenig binary log events.');
|
||||
|
||||
process.on('SIGINT', async function() {
|
||||
|
@ -98,7 +98,7 @@ async function flushQueue() {
|
|||
for (const fk of fks) ids.push([fk]);
|
||||
await db.query(config.addQuery, [ids]);
|
||||
await db.query(
|
||||
'REPLACE INTO `util`.`asyncQueue` (`code`, `logName`, `position`) VALUES (?, ?, ?)',
|
||||
'REPLACE INTO `util`.`binlogQueue` (`code`, `logName`, `position`) VALUES (?, ?, ?)',
|
||||
[config.queue, filename, nextPosition]
|
||||
);
|
||||
fks.clear();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
CREATE TABLE `util`.`asyncQueue`(
|
||||
CREATE TABLE `util`.`binlogQueue`(
|
||||
`code` VARCHAR(255) NOT NULL,
|
||||
`logName` VARCHAR(255) NOT NULL,
|
||||
`position` BIGINT UNSIGNED NOT NULL,
|
||||
|
@ -9,5 +9,6 @@ CREATE TABLE `util`.`asyncQueue`(
|
|||
CREATE USER 'zongji'@'%' IDENTIFIED BY 'password';
|
||||
GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'zongji'@'%';
|
||||
|
||||
GRANT INSERT, DELETE ON `util`.`asyncQueue` TO 'zongji'@'%';
|
||||
GRANT INSERT, DELETE ON `util`.* TO 'zongji'@'%';
|
||||
GRANT INSERT ON `hedera`.`orderRecalc` TO 'zongji'@'%';
|
||||
GRANT INSERT ON `vn`.`ticketRecalc` TO 'zongji'@'%';
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
|
||||
DROP TABLE IF EXISTS `util`.`asyncQueue`;
|
||||
DROP TABLE IF EXISTS `util`.`binlogQueue`;
|
||||
DROP USER 'zongji'@'%';
|
||||
|
|
Loading…
Reference in New Issue