Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
acattaneoacn committed May 9, 2023
2 parents 112f7f4 + 9254499 commit b13cce5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
34 changes: 34 additions & 0 deletions command/scanManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
Expand All @@ -180,6 +185,9 @@ const scan = async (jobId) => {
end_at: Date.now(),
});

const pidKilled = await killProcessByName("Chromium");
console.log("PID KILLED: ", pidKilled);

return false;
}
};
Expand Down Expand Up @@ -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;
}
};
3 changes: 3 additions & 0 deletions controller/PA2026/integrationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
mapPA2026Body,
mapPA2026BodyUrlNotExists,
} from "../../utils/utils";
import { Op } from "sequelize";

const retrieveToken = async () => {
try {
Expand Down Expand Up @@ -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",
},
});

Expand Down
25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b13cce5

Please sign in to comment.