diff --git a/command/scanManager.ts b/command/scanManager.ts index 4050119..8670595 100644 --- a/command/scanManager.ts +++ b/command/scanManager.ts @@ -27,6 +27,8 @@ import { } from "../controller/PA2026/integrationController"; import { urlExists } from "../utils/utils"; import { entityController } from "../controller/entityController"; +import psList from "ps-list"; +import treeKill from "tree-kill"; dbSM .authenticate() @@ -171,6 +173,9 @@ const scan = async (jobId) => { ); console.log("JOB DELETED: ", jobDeleted); + const pidKilled = await killProcessByName("Chromium"); + console.log("PID KILLED: ", pidKilled); + return true; } catch (e) { console.log("SCAN EXCEPTION: ", e.toString()); @@ -180,6 +185,9 @@ const scan = async (jobId) => { end_at: Date.now(), }); + const pidKilled = await killProcessByName("Chromium"); + console.log("PID KILLED: ", pidKilled); + return false; } }; @@ -247,3 +255,29 @@ const uploadFiles = async ( }; } }; + +const killProcessByName = async (name: string) => { + const pidKilled = []; + + try { + const list = await psList(); + + for (const element of list) { + try { + if (element.name === name) { + await treeKill(element.pid); + pidKilled.push(element.pid); + } + } catch (e) { + console.log("ELEMENT IN ERROR: ", element); + console.log("KILL PROCESS BY NAME FOR-STATEMENT EXCEPTION: ", e); + } + } + + return pidKilled; + } catch (e) { + console.log("KILL PROCESS BY NAME EXCEPTION: ", e); + + return pidKilled; + } +}; diff --git a/controller/PA2026/integrationController.ts b/controller/PA2026/integrationController.ts index 813debd..f980d80 100644 --- a/controller/PA2026/integrationController.ts +++ b/controller/PA2026/integrationController.ts @@ -19,6 +19,7 @@ import { mapPA2026Body, mapPA2026BodyUrlNotExists, } from "../../utils/utils"; +import { Op } from "sequelize"; const retrieveToken = async () => { try { @@ -185,6 +186,8 @@ const pushResult = async ( const countJobsFromEntityId = await jobDefine(dbSM).count({ where: { entity_id: entity.id, + [Op.not]: [{ preserve_reason: preserveReasons[0] }], + data_sent_status: "COMPLETED", }, }); diff --git a/package-lock.json b/package-lock.json index b282220..3a9c376 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,12 +24,14 @@ "mysql2": "^2.3.3", "nodemon": "^2.0.16", "npm-run-all": "^4.1.5", - "pa-website-validator": "github:italia/pa-website-validator#v2.3.0", + "pa-website-validator": "github:italia/pa-website-validator#v2.3.2", "pg": "^8.7.3", + "ps-list": "^8.1.1", "redis": "^4.1.0", "sequelize": "^6.6.5", "swagger-jsdoc": "^6.1.0", "swagger-ui-express": "^4.4.0", + "tree-kill": "^1.2.2", "ts-node": "^10.7.0", "typescript": "^4.6.4", "winston": "^3.7.2", @@ -4949,8 +4951,8 @@ } }, "node_modules/pa-website-validator": { - "version": "2.3.0", - "resolved": "git+ssh://git@github.com/italia/pa-website-validator.git#4e70a2b30744a69d8f1a9707225e2fec4fb8eea1", + "version": "2.3.2", + "resolved": "git+ssh://git@github.com/italia/pa-website-validator.git#de04ed66d14f3b1a6be81da5302b74ef6fee0f91", "license": "BSD-3-Clause", "dependencies": { "axios": "^1.1.3", @@ -6507,6 +6509,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/triple-beam": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", @@ -10825,8 +10835,8 @@ "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" }, "pa-website-validator": { - "version": "git+ssh://git@github.com/italia/pa-website-validator.git#4e70a2b30744a69d8f1a9707225e2fec4fb8eea1", - "from": "pa-website-validator@github:italia/pa-website-validator#v2.3.0", + "version": "git+ssh://git@github.com/italia/pa-website-validator.git#de04ed66d14f3b1a6be81da5302b74ef6fee0f91", + "from": "pa-website-validator@github:italia/pa-website-validator#v2.3.2", "requires": { "axios": "^1.1.3", "cheerio": "^1.0.0-rc.10", @@ -11923,6 +11933,11 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==" + }, "triple-beam": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", diff --git a/package.json b/package.json index 5ee5bcb..6c5c3ea 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,14 @@ "mysql2": "^2.3.3", "nodemon": "^2.0.16", "npm-run-all": "^4.1.5", - "pa-website-validator": "github:italia/pa-website-validator#v2.3.0", + "pa-website-validator": "github:italia/pa-website-validator#v2.3.2", "pg": "^8.7.3", + "ps-list": "^8.1.1", "redis": "^4.1.0", "sequelize": "^6.6.5", "swagger-jsdoc": "^6.1.0", "swagger-ui-express": "^4.4.0", + "tree-kill": "^1.2.2", "ts-node": "^10.7.0", "typescript": "^4.6.4", "winston": "^3.7.2",