Compare commits

..

1 Commits

Author SHA1 Message Date
Alex Moreno 64e90b9d61 refactor: use getExpeditionPallet_build and simplify code
gitea/vn-rfid/pipeline/head This commit looks good Details
2023-01-25 13:22:45 +01:00
25 changed files with 118 additions and 5506 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
node_modules
config.*.yml
config.local.yml

View File

@ -3,6 +3,6 @@
// Carácter predeterminado de final de línea.
"files.eol": "\n",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
"source.fixAll.eslint": true
}
}

View File

@ -4,10 +4,6 @@ COPY package.json ./
RUN npm install
COPY db db
COPY src src
COPY util util
COPY \
server.js \
config.yml \
npm-config.npmrc \
./
COPY config.yml ./
COPY server.js ./
CMD ["node", "server.js"]

58
Jenkinsfile vendored
View File

@ -2,54 +2,64 @@
pipeline {
agent any
options {
disableConcurrentBuilds()
}
environment {
PROJECT_NAME = 'vn-rfid'
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
}
stages {
stage('Setup') {
stage('Checkout') {
steps {
echo "NODE_NAME: ${env.NODE_NAME}"
echo "WORKSPACE: ${env.WORKSPACE}"
script {
switch (env.BRANCH_NAME) {
case 'master':
env.NODE_ENV = 'production'
break
}
}
setEnv()
}
}
stage('Build') {
when {
when { anyOf {
branch 'master'
}
}}
environment {
CREDENTIALS = credentials('docker-registry')
}
steps {
script {
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
}
dockerBuild()
}
}
stage('Deploy') {
when {
when { anyOf {
branch 'master'
}}
environment {
DOCKER_HOST = "${env.SWARM_HOST}"
}
steps {
script {
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
}
withKubeConfig([
serverUrl: "$KUBERNETES_API",
credentialsId: 'kubernetes',
namespace: 'vn-rfid'
]) {
sh 'kubectl set image deployment/vn-rfid vn-rfid=$REGISTRY/vn-rfid:$VERSION'
}
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
}
}
}
post {
always {
setEnv()
sendEmail()
script {
if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return;
try {
mail(
to: env.COMMITTER_EMAIL,
subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}",
body: "Check status at ${env.BUILD_URL}"
)
} catch (e) {
echo e.toString()
}
}
}
}
}
}

View File

@ -11,12 +11,9 @@ $ sudo npm install -g pino-pretty
Launch application in developer environment.
```
$ npm run start
or
$ npm run start | pino-pretty
```
For test.
```
DELETE expedition in vn.expeditionScan
DELETE expedition in vn.expeditionScan
```

View File

@ -1,14 +1,13 @@
arcId: 1
port: 1234
ip: 1.2.3.4
env: dev
interval: 3000
interval: 1000
reconnectInterval: 5000
counterInterval: 1000
db:
host: host
port: 3307
database: srt
user: user
password: password
multipleStatements: false
multipleStatements: true
insecureAuth: true

View File

@ -1,4 +0,0 @@
import mysql from 'mysql2/promise';
import getConfig from '../util/getConfig.js';
export default mysql.createPool(getConfig('production').db);

View File

@ -1,6 +0,0 @@
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,7 +1,20 @@
version: '3.7'
services:
main:
image: registry.verdnatura.es/vn-rfid:${VERSION:?}
image: registry.verdnatura.es/vn-rfid:${BRANCH_NAME:?}
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile
ports:
- 8888
configs:
- source: config
target: /app/config.local.yml
deploy:
placement:
constraints:
- node.role == worker
configs:
config:
external: true
name: vn-rfid_config

View File

@ -1 +0,0 @@
engine-strict=true

285
package-lock.json generated
View File

@ -598,11 +598,6 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/colorette": {
"version": "2.0.19",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz",
"integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ=="
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -658,14 +653,6 @@
"node": ">= 8"
}
},
"node_modules/dateformat": {
"version": "4.6.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz",
"integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==",
"engines": {
"node": "*"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -1088,11 +1075,6 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/fast-copy": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-3.0.0.tgz",
"integrity": "sha512-4HzS+9pQ5Yxtv13Lhs1Z1unMXamBdn5nA4bEi1abYpDNSpSp7ODYQ1KPMF6nTatfEzgH6/zPvXKU1zvHiUjWlA=="
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@ -1116,11 +1098,6 @@
"node": ">=6"
}
},
"node_modules/fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA=="
},
"node_modules/file-entry-cache": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
@ -1385,73 +1362,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/help-me": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/help-me/-/help-me-4.2.0.tgz",
"integrity": "sha512-TAOnTB8Tz5Dw8penUuzHVrKNKlCIbwwbHnXraNJxPwf8LRtE2HlM84RYuezMFcwOJmoYOCWVDyJ8TQGxn9PgxA==",
"dependencies": {
"glob": "^8.0.0",
"readable-stream": "^3.6.0"
}
},
"node_modules/help-me/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/help-me/node_modules/glob": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^5.0.1",
"once": "^1.3.0"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/help-me/node_modules/minimatch": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
"dependencies": {
"brace-expansion": "^2.0.1"
},
"engines": {
"node": ">=10"
}
},
"node_modules/help-me/node_modules/readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/help-me/node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
@ -1638,14 +1548,6 @@
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
},
"node_modules/joycon": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz",
"integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==",
"engines": {
"node": ">=10"
}
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@ -1813,14 +1715,6 @@
"node": "*"
}
},
"node_modules/minimist": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -2179,44 +2073,6 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/pino-pretty": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-9.1.1.tgz",
"integrity": "sha512-iJrnjgR4FWQIXZkUF48oNgoRI9BpyMhaEmihonHeCnZ6F50ZHAS4YGfGBT/ZVNsPmd+hzkIPGzjKdY08+/yAXw==",
"dependencies": {
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-copy": "^3.0.0",
"fast-safe-stringify": "^2.1.1",
"help-me": "^4.0.1",
"joycon": "^3.1.1",
"minimist": "^1.2.6",
"on-exit-leak-free": "^2.1.0",
"pino-abstract-transport": "^1.0.0",
"pump": "^3.0.0",
"readable-stream": "^4.0.0",
"secure-json-parse": "^2.4.0",
"sonic-boom": "^3.0.0",
"strip-json-comments": "^3.1.1"
},
"bin": {
"pino-pretty": "bin.js"
}
},
"node_modules/pino-pretty/node_modules/readable-stream": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.3.0.tgz",
"integrity": "sha512-MuEnA0lbSi7JS8XM+WNJlWZkHAAdm7gETHdFK//Q/mChGyj2akEFtdLZh32jSdkWGbRwCW9pn6g3LWDdDeZnBQ==",
"dependencies": {
"abort-controller": "^3.0.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"process": "^0.11.10"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/pino-std-serializers": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.1.0.tgz",
@ -2510,11 +2366,6 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/secure-json-parse": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz",
"integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw=="
},
"node_modules/semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
@ -2890,11 +2741,6 @@
"punycode": "^2.1.0"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
@ -3376,11 +3222,6 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"colorette": {
"version": "2.0.19",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz",
"integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -3424,11 +3265,6 @@
"which": "^2.0.1"
}
},
"dateformat": {
"version": "4.6.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz",
"integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA=="
},
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -3743,11 +3579,6 @@
}
}
},
"fast-copy": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-3.0.0.tgz",
"integrity": "sha512-4HzS+9pQ5Yxtv13Lhs1Z1unMXamBdn5nA4bEi1abYpDNSpSp7ODYQ1KPMF6nTatfEzgH6/zPvXKU1zvHiUjWlA=="
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@ -3768,11 +3599,6 @@
"resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.1.2.tgz",
"integrity": "sha512-+0em+Iya9fKGfEQGcd62Yv6onjBmmhV1uh86XVfOU8VwAe6kaFdQCWI9s0/Nnugx5Vd9tdbZ7e6gE2tR9dzXdw=="
},
"fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA=="
},
"file-entry-cache": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
@ -3969,63 +3795,6 @@
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
},
"help-me": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/help-me/-/help-me-4.2.0.tgz",
"integrity": "sha512-TAOnTB8Tz5Dw8penUuzHVrKNKlCIbwwbHnXraNJxPwf8LRtE2HlM84RYuezMFcwOJmoYOCWVDyJ8TQGxn9PgxA==",
"requires": {
"glob": "^8.0.0",
"readable-stream": "^3.6.0"
},
"dependencies": {
"brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"requires": {
"balanced-match": "^1.0.0"
}
},
"glob": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^5.0.1",
"once": "^1.3.0"
}
},
"minimatch": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
"requires": {
"brace-expansion": "^2.0.1"
}
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"requires": {
"safe-buffer": "~5.2.0"
}
}
}
},
"http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
@ -4159,11 +3928,6 @@
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
},
"joycon": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz",
"integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw=="
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@ -4293,11 +4057,6 @@
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g=="
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -4578,40 +4337,6 @@
}
}
},
"pino-pretty": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-9.1.1.tgz",
"integrity": "sha512-iJrnjgR4FWQIXZkUF48oNgoRI9BpyMhaEmihonHeCnZ6F50ZHAS4YGfGBT/ZVNsPmd+hzkIPGzjKdY08+/yAXw==",
"requires": {
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-copy": "^3.0.0",
"fast-safe-stringify": "^2.1.1",
"help-me": "^4.0.1",
"joycon": "^3.1.1",
"minimist": "^1.2.6",
"on-exit-leak-free": "^2.1.0",
"pino-abstract-transport": "^1.0.0",
"pump": "^3.0.0",
"readable-stream": "^4.0.0",
"secure-json-parse": "^2.4.0",
"sonic-boom": "^3.0.0",
"strip-json-comments": "^3.1.1"
},
"dependencies": {
"readable-stream": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.3.0.tgz",
"integrity": "sha512-MuEnA0lbSi7JS8XM+WNJlWZkHAAdm7gETHdFK//Q/mChGyj2akEFtdLZh32jSdkWGbRwCW9pn6g3LWDdDeZnBQ==",
"requires": {
"abort-controller": "^3.0.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"process": "^0.11.10"
}
}
}
},
"pino-std-serializers": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.1.0.tgz",
@ -4818,11 +4543,6 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"secure-json-parse": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz",
"integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw=="
},
"semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
@ -5115,11 +4835,6 @@
"punycode": "^2.1.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",

View File

@ -3,14 +3,10 @@
"version": "1.0.0",
"author": "Verdnatura Levante SL",
"description": "rfid backend",
"main": "server.js",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon ./server.js | pino-pretty "
},
"engines": {
"node": ">=18",
"npm": ">=8"
"start": "nodemon ./server.js"
},
"keywords": [],
"license": "GPL-3.0",

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +0,0 @@
INSERT INTO vn.arcRead (id, printerFk, ip, counter, error, minimum) VALUES(1, NULL, '10.1.16.1', 17, NULL, 5);
CREATE TABLE `rfidTest` (
`palletFk` int(11) DEFAULT NULL,
`expeditionFk` int(11) DEFAULT NULL,
`created` timestamp NULL DEFAULT current_timestamp(),
`peakRssi` int(11) DEFAULT NULL,
`antenna` int(11) DEFAULT NULL,
`attempt` int(11) DEFAULT NULL,
`power` int(11) DEFAULT NULL,
`sensitivity` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
CREATE TABLE `algorithm` (
`palletFk` int(11) DEFAULT NULL,
`expeditionArray` text DEFAULT NULL,
`created` timestamp NULL DEFAULT current_timestamp(),
`expeditionCount` int(11) DEFAULT NULL,
`model` text DEFAULT NULL,
`attempt` int(11) DEFAULT NULL,
`power` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
-- vn.trys definition
-- vn.trys definition
CREATE TABLE `vn`.`trys` (
`palletFk` int(11) NOT NULL,
`missing` text DEFAULT NULL,
`powerType` varchar(255) NOT NULL DEFAULT 'V17',
`extra` varchar(100) DEFAULT NULL,
`antennaReads` text DEFAULT NULL,
`observationExtra` text DEFAULT NULL,
`observationMissing` text DEFAULT NULL,
`timestamp` timestamp NULL DEFAULT current_timestamp(),
`antenna1` int(11) DEFAULT NULL,
`antenna2` int(11) DEFAULT NULL,
`antenna3` int(11) DEFAULT NULL,
`antenna4` int(11) DEFAULT NULL,
`total` varchar(100) DEFAULT NULL,
PRIMARY KEY (`palletFk`,`powerType`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`trys_beforeUpdate`
BEFORE UPDATE ON `trys`
FOR EACH ROW
BEGIN
IF (NEW.missing > OLD.missing) THEN
CALL util.throw('New missing greater than old');
END IF;
END
-- powerTypes [PW13, PW15, V17, V19]

View File

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

View File

@ -1,15 +0,0 @@
import con from '../db/connect.js';
let lastCounter;
export default async(size, arcId) => {
if (lastCounter == size) return;
console.logger.info(`COUNTER: SIZE:${size} ARC_ID:${arcId}`);
await con.query(`
UPDATE vn.arcRead
SET counter = ?,
error = NULL
WHERE id = ?;
`, [size, arcId]);
lastCounter = size;
};

View File

@ -1,12 +1,13 @@
import con from '../db/connect.js';
import t from '../util/translator.js';
export default async(rfids, arcId) => {
try {
console.log(Array.from(rfids));
await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(rfids), arcId, null]);
} catch (error) {
console.log(error);
await con.query(`UPDATE vn.arcRead SET error = ?, counter = NULL WHERE id = ?;`, [t(error.sqlMessage), arcId]);
}
export default async rfids => {
const codes = new Set();
for (let rfid of rfids)
codes.add(rfid.code);
console.logger.info('PRINTING...');
const palletId = await con.query(`SELECT vn.getExpeditionPallet_build(?,?,?);`, [Array.from(codes), 1, null]);
if (!palletId)
console.logger.info({error: 'ERROR_CREATING_PALLET', expeditions: rfids});
};

View File

@ -2,34 +2,28 @@ export default async data => {
data = data.toString();
const crudeRfids = data.split('\n');
const rfidsParsed = new Set();
const rfidsParsedExtended = [];
const RFID_PREFIX = 'AABB';
const rfidsParsed = [];
for (let crudeRfid of crudeRfids) {
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
const jsonResult = JSON.parse(crudeRfid);
let epcHex = jsonResult?.tagInventoryEvent?.epcHex;
if (!epcHex) continue;
if (epcHex.search(RFID_PREFIX) == -1) continue;
if (!epcHex) return;
if (epcHex.search('AABB') == -1) continue;
epcHex = epcHex.replace(RFID_PREFIX, '');
epcHex = epcHex.replace('AABB', '');
epcHex = epcHex.substring(0, 1) == 0 ? epcHex.substring(1) : epcHex;
const rfidParsed = {
code: parseInt(epcHex),
created: jsonResult.timestamp,
peakRssi: jsonResult.tagInventoryEvent.peakRssiCdbm,
count: 1,
antenna: jsonResult.tagInventoryEvent.antennaPort,
transmitPowerCdbm: jsonResult.tagInventoryEvent.transmitPowerCdbm
antenna: jsonResult.tagInventoryEvent.antennaPort
};
rfidsParsedExtended.push(rfidParsed);
rfidsParsed.add(rfidParsed.code);
rfidsParsed.push(rfidParsed);
}
}
return {codes: rfidsParsed, extended: rfidsParsedExtended};
return rfidsParsed;
};

View File

@ -1,15 +1,13 @@
import got from 'got';
import rfidParser from './rfidParser.js';
import newPallet from './newPallet.js';
import debug from '../util/debugStream.js';
import counter from './counter.js';
import debug from '../util/streamDebug.js';
let interval;
let counterInterval;
export default async(conf, cb) => {
let rfidbuffer = new Set();
let rfidbufferExtend = [];
let rfidbuffer = [];
let rfidbufferSet = [new Set(), new Set(), new Set(), new Set()];
const stream = got.stream(`http://${conf.ip}/api/v1/data/stream`);
@ -17,19 +15,15 @@ export default async(conf, cb) => {
.on('data', async value => {
const parsed = await rfidParser(value);
if (!parsed.codes.size) return;
rfidbuffer = new Set([...rfidbuffer, ...parsed.codes]);
rfidbufferExtend = rfidbufferExtend.concat(parsed.extended);
if (parsed)
rfidbuffer = rfidbuffer.concat(parsed);
// debug({codes: rfidbuffer, extended: rfidbufferExtend}, conf);
debug(rfidbuffer, rfidbufferSet);
if (rfidbuffer.size) {
clearTimeout(interval);
if (rfidbuffer.length && parsed.length) {
clearInterval(interval);
interval = null;
interval = setTimeout(createPallet, conf.interval);
if (!counterInterval)
counterInterval = setTimeout(counterIntervalManager, conf.counterInterval);
}
})
.on('error', e => {
@ -37,17 +31,11 @@ export default async(conf, cb) => {
});
function createPallet() {
clearTimeout(interval);
clearInterval(interval); // try remove
if (!conf.minimum || rfidbuffer.size > conf.minimum)
newPallet(rfidbuffer, conf.arcId);
rfidbuffer = new Set();
rfidbufferExtend = [];
counterIntervalManager();
}
newPallet(rfidbuffer);
function counterIntervalManager() {
counterInterval = null;
counter(rfidbuffer.size, conf.arcId);
rfidbuffer = [];
rfidbufferSet = [new Set(), new Set(), new Set(), new Set()];
}
};

View File

@ -1,93 +0,0 @@
import con from '../db/connect.js';
import conMaster from '../db/connectMaster.js';
import fs from 'node:fs';
export default async uniqueRead => {
const reads = new Set([
...uniqueRead[0],
...uniqueRead[1],
...uniqueRead[2],
...uniqueRead[3],
]);
console.log('reads: ', [...reads][0]);
let [[palletFk]] = await conMaster.query(
`SELECT palletFk FROM expeditionScan WHERE expeditionFk IN (?)`,
[[...reads].join(',')]
);
palletFk = palletFk?.palletFk;
console.log('palletFk: ', palletFk);
if (!palletFk) return console.log('LA EXPEDICION NO esta en el pallet');
let [realExpeditions] = await conMaster.query(
`SELECT ep.id, e.id, ps.printerRfidFk, ps.code, es.palletFk
FROM expeditionPallet ep
JOIN expeditionScan es ON es.palletFk = ep.id
JOIN expedition e ON e.id = es.expeditionFk
JOIN host h ON h.code = e.hostFk COLLATE utf8mb3_unicode_ci
JOIN packingSite ps ON ps.hostFk = h.id
WHERE ep.id = ?
AND ps.printerRfidFk`,
[palletFk]
);
realExpeditions = realExpeditions.map(r => r.id);
console.log('realExpeditions: ', realExpeditions.length);
if (realExpeditions.length != reads.size)
console.logger.warn('MISSING EXPEDITIONS');
const missing = realExpeditions.filter(x => ![...reads].includes(x));
const extra = [...reads].filter(x => !realExpeditions.includes(x));
if (missing.length) console.warn('MISSING:', missing.length, missing);
if (extra.length) console.warn('EXTRA:', extra.length, extra);
try {
const [[currentMissings]] = await con.query('SELECT missing FROM trys WHERE palletFk = ?', palletFk);
if (currentMissings?.missing < missing.length) return console.log('PREVENT REPLACE', currentMissings.missing, missing.length);
await con.query(
`
REPLACE trys
SET palletFk = ?,
missing = ?,
extra = ?,
total = ?,
powerType = ?,
observationExtra = ?,
observationMissing = ?,
antenna1 = ?,
antenna2 = ?,
antenna3 = ?,
antenna4 = ?
`,
[
palletFk,
missing.length,
extra.length,
realExpeditions.length,
'VDT3',
extra.join(','),
missing.join(','),
uniqueRead[0].size,
uniqueRead[1].size,
uniqueRead[2].size,
uniqueRead[3].size,
]
);
await saveTable();
} catch (e) {
console.log('error debugging', palletFk, e);
}
};
async function saveTable() {
const [table] = await con.query(`SELECT * FROM trys WHERE DATE(timestamp) = CURDATE()`);
const date = new Date().toISOString().split('T')[0];
if (!table.length) return;
const file = fs.createWriteStream(`${date}.txt`);
file.on('error', function(err) {
console.error(err);
});
table.forEach(function(v) {
file.write(JSON.stringify(v) + '\n');
});
file.end();
}

View File

@ -1,21 +0,0 @@
import debugMissing from './debugMissing.js';
export default async(parsed, conf) => {
if (conf.env != 'dev') return;
// TOTAL READS BY ANTENNA
const totalRead = [0, 0, 0, 0];
for (let read of parsed.extended)
totalRead[read.antenna - 1]++;
console.log('TOTAL READ ANTENNA:', totalRead);
// UNIQUE READS BY ANTENNA
const uniqueRead = [new Set(), new Set(), new Set(), new Set()];
for (let read of parsed.extended)
uniqueRead[read.antenna - 1].add(read.code);
console.log('UNIQUE READ ANTENNA:', uniqueRead[0].size, uniqueRead[1].size, uniqueRead[2].size, uniqueRead[3].size);
debugMissing(uniqueRead);
console.log('----------------------------------------------------------------');
};

View File

@ -2,10 +2,10 @@ import yml from 'require-yml';
import path from 'path';
import fs from 'fs-extra';
export default function getConfig(env = 'local') {
export default function getConfig() {
const {pathname: root} = new URL('../', import.meta.url);
let conf = yml(path.join(root, 'config.yml'));
const localConfFile = path.join(root, `config.${env}.yml`);
const localConfFile = path.join(root, 'config.local.yml');
if (fs.existsSync(localConfFile))
conf = Object.assign({}, conf, yml(localConfFile));

View File

@ -1 +0,0 @@
TRUCK_NOT_AVAILABLE: No hay un camión disponible

21
util/streamDebug.js Normal file
View File

@ -0,0 +1,21 @@
export default (rfidbuffer, rfidbufferSet) => {
if (conf.env != 'dev') return;
let totalBuffer = rfidbuffer.map(rfid => rfid.code);
let totalBufferSet = new Set(totalBuffer);
console.log('TOTAL BUFFER: ', totalBufferSet.size);
const totalRead = [0, 0, 0, 0];
for (let buffer of rfidbuffer)
totalRead[buffer.antenna - 1]++;
console.log('TOTAL READ ANTENNA:', totalRead);
for (let buffer of parsed)
rfidbufferSet[buffer.antenna - 1].add(buffer.code);
console.log('UNIQUE READ ANTENNA:', rfidbufferSet[0].size, rfidbufferSet[1].size, rfidbufferSet[2].size, rfidbufferSet[3].size);
for (const [index, set] of rfidbufferSet.entries()) {
if (((set.size * 100) / totalBufferSet.size) < 25)
console.log('[WARNING_ANTENNA]: ', index, ' ONLY ', set.size);
}
console.log('----------------------------------------------------------------');
};

View File

@ -1,8 +0,0 @@
import yml from 'require-yml';
import path from 'path';
export default function t(expression) {
const {pathname: root} = new URL('./locale', import.meta.url);
let es = yml(path.join(root, 'es.yml')) || {};
return es[expression] || expression;
}