ql-agent 1.1.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +49 -19
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
// index.js
|
|
2
|
-
const axios = require('axios');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
1
|
+
// // index.js
|
|
2
|
+
// const axios = require('axios');
|
|
3
|
+
// const os = require('os');
|
|
4
|
+
// const fs = require('fs');
|
|
5
|
+
// const path = require('path');
|
|
6
|
+
|
|
7
|
+
// const { PrismaClient } = require('@prisma/client');
|
|
8
|
+
|
|
9
|
+
// const prisma = new PrismaClient({
|
|
10
|
+
// log: process.env.NODE_ENV === 'development'
|
|
11
|
+
// ? ['query', 'error', 'warn']
|
|
12
|
+
// : ['error'],
|
|
13
|
+
// transactionOptions: {
|
|
14
|
+
// maxWait: 10000, // temps max d'attente pour demarrer la transaction
|
|
15
|
+
// timeout: 30000, // duree max de la transaction (BD distante)
|
|
16
|
+
// },
|
|
17
|
+
// });
|
|
18
|
+
|
|
19
|
+
// // 🔎 Test de connexion au démarrage
|
|
20
|
+
// async function connectDatabase() {
|
|
21
|
+
// try {
|
|
22
|
+
// await prisma.$connect();
|
|
23
|
+
// console.log("✅ Connexion à la base de données établie avec succès");
|
|
24
|
+
// } catch (error) {
|
|
25
|
+
// console.error("❌ Impossible de se connecter à la base de données");
|
|
26
|
+
// console.error(error.message);
|
|
27
|
+
// process.exit(1); // Arrête le serveur si la DB est inaccessible
|
|
28
|
+
// }
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
// connectDatabase();
|
|
32
|
+
|
|
33
|
+
// module.exports = prisma;
|
|
6
34
|
|
|
7
35
|
function initAgent(config) {
|
|
8
36
|
const { relay, token, baseDir } = config;
|
|
@@ -10,22 +38,24 @@ function initAgent(config) {
|
|
|
10
38
|
let agentId = null;
|
|
11
39
|
|
|
12
40
|
// Enregistrement de l'agent auprès du serveur relay
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
41
|
+
async function register() {
|
|
42
|
+
try {
|
|
43
|
+
const payload = {
|
|
44
|
+
hostname: os.hostname(),
|
|
45
|
+
platform: os.platform()
|
|
46
|
+
};
|
|
19
47
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
const res = await axios.post(`${relay}/register`, { payload }, {
|
|
49
|
+
headers: { "x-relay-token": token }
|
|
50
|
+
});
|
|
23
51
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
52
|
+
agentId = res.data.id;
|
|
53
|
+
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// retry dans 10s si échec
|
|
56
|
+
setTimeout(register, 10000);
|
|
28
57
|
}
|
|
58
|
+
}
|
|
29
59
|
|
|
30
60
|
// Envoi du heartbeat
|
|
31
61
|
async function heartbeat() {
|
|
@@ -77,7 +107,7 @@ function initAgent(config) {
|
|
|
77
107
|
}
|
|
78
108
|
|
|
79
109
|
// Intervalles
|
|
80
|
-
setInterval(register,
|
|
110
|
+
setInterval(register, 90000);
|
|
81
111
|
setInterval(heartbeat, 10000);
|
|
82
112
|
setInterval(poll, 5000);
|
|
83
113
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ql-agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"start": "
|
|
8
|
+
"start": "nodemon index.js"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"axios": "^1.14.0"
|
|
14
|
+
"axios": "^1.14.0",
|
|
15
|
+
"nodemon": "^3.1.14"
|
|
15
16
|
}
|
|
16
17
|
}
|