refs #5144 add minimum filter #4

Merged
alexm merged 1 commits from 5144-setMinimum into master 2023-05-18 11:30:43 +00:00
4 changed files with 23 additions and 6 deletions

View File

@ -11,6 +11,10 @@ $ sudo npm install -g pino-pretty
Launch application in developer environment. Launch application in developer environment.
``` ```
$ npm run start $ npm run start
or
$ npm run start | pino-pretty
``` ```
For test. For test.

6
db/querys/getArcs.js Normal file
View File

@ -0,0 +1,6 @@
import con from '../connect.js';
export default async() => {
const [arcs] = await con.query(`SELECT id as arcId, printerFk, ip, minimum FROM vn.arcRead;`);
return arcs;
};

View File

@ -1,15 +1,21 @@
import stream from './src/stream.js'; import stream from './src/stream.js';
import getConfig from './util/getConfig.js'; import getConfig from './util/getConfig.js';
import logger from 'pino'; import logger from 'pino';
import getArcs from './db/querys/getArcs.js';
console.logger = logger(); console.logger = logger();
function main() { async function main(arcId) {
const conf = getConfig(); const conf = getConfig();
stream(conf, e => { for (let arc of await getArcs()) {
const config = Object.assign({}, conf, arc);
if (arcId && arcId != arc.arcId) continue;
stream(config, e => {
console.logger.error(e); console.logger.error(e);
setTimeout(main, conf.reconnectInterval); setTimeout(main, config.reconnectInterval, config.arcId);
}); });
}
} }
main(); main();

View File

@ -39,6 +39,7 @@ export default async(conf, cb) => {
function createPallet() { function createPallet() {
clearTimeout(interval); clearTimeout(interval);
if (!conf.minimum || rfidbuffer.size > conf.minimum)
newPallet(rfidbuffer, conf.arcId); newPallet(rfidbuffer, conf.arcId);
rfidbuffer = new Set(); rfidbuffer = new Set();