@tiledesk/tiledesk-server 2.4.29 → 2.4.30
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -16,6 +16,8 @@ constructor() {
|
|
16
16
|
this.queryAfterTimeout = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_AFTER_TIMEOUT) || 2 * 24 * 60 * 60 * 1000; //two days ago //172800000 two days // 86400000 a day
|
17
17
|
this.queryLimit = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_QUERY_LIMIT) || 10;
|
18
18
|
this.queryProject = process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_QUERY_FILTER_ONLY_PROJECT; //example in PRE: {"$in":["5fc224ce05416200342af18a","5fb3e3cb0150a00034ab77d5"]}
|
19
|
+
this.delayBeforeClosing = parseInt(process.env.CLOSE_BOT_UNRESPONSIVE_REQUESTS_DELAY) || 1000;
|
20
|
+
// winston.info("delayBeforeClosing: "+ this.delayBeforeClosing);
|
19
21
|
|
20
22
|
if (this.queryProject) {
|
21
23
|
winston.info("CloseBotUnresponsiveRequestTask filter only by projects enabled: " + this.queryProject );
|
@@ -62,10 +64,12 @@ scheduleUnresponsiveRequests() {
|
|
62
64
|
|
63
65
|
|
64
66
|
findUnresponsiveRequests() {
|
65
|
-
|
67
|
+
var that = this;
|
68
|
+
|
66
69
|
// db.getCollection('requests').find({"hasBot":true, "status": { "$lt": 1000 }, "createdAt": { "$lte" :new ISODate("2020-11-28T20:15:31Z")} }).count()
|
67
70
|
|
68
71
|
|
72
|
+
// TODO escludi i ticket offline
|
69
73
|
var query = {hasBot:true, status: { $lt: 1000 }, createdAt: { $lte :new Date(Date.now() - this.queryAfterTimeout ).toISOString()} };
|
70
74
|
|
71
75
|
if (this.queryProject) {
|
@@ -73,6 +77,7 @@ findUnresponsiveRequests() {
|
|
73
77
|
}
|
74
78
|
|
75
79
|
|
80
|
+
// TODO dovrei fare una query escludendo tutti gli id_project su cui è disabilitato oppure dovrei salvare un attribute in ogni singola request
|
76
81
|
|
77
82
|
winston.debug("CloseBotUnresponsiveRequestTask query",query);
|
78
83
|
|
@@ -84,6 +89,9 @@ findUnresponsiveRequests() {
|
|
84
89
|
winston.error("CloseBotUnresponsiveRequestTask error getting unresponsive requests ", err);
|
85
90
|
return 0;
|
86
91
|
}
|
92
|
+
|
93
|
+
// winston.info("delayBeforeClosing: "+ that.delayBeforeClosing);
|
94
|
+
|
87
95
|
if (!requests || (requests && requests.length==0)) {
|
88
96
|
winston.verbose("CloseBotUnresponsiveRequestTask no unresponsive requests found ");
|
89
97
|
return 0;
|
@@ -91,24 +99,32 @@ findUnresponsiveRequests() {
|
|
91
99
|
|
92
100
|
winston.info("CloseBotUnresponsiveRequestTask: found " + requests.length + " unresponsive requests");
|
93
101
|
winston.debug("CloseBotUnresponsiveRequestTask: found unresponsive requests ", requests);
|
94
|
-
|
95
|
-
requests.forEach(request => {
|
96
102
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
103
|
+
let i = 0;
|
104
|
+
let delay = this.delayBeforeClosing*i;
|
105
|
+
// winston.info("delay" + delay);
|
106
|
+
|
107
|
+
requests.forEach(request => {
|
108
|
+
i++;
|
109
|
+
setTimeout(function(){
|
110
|
+
|
111
|
+
// TODO aggiungi uno sleep
|
112
|
+
winston.debug("********unresponsive request ", request);
|
113
|
+
|
114
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
115
|
+
const closed_by = "_bot_unresponsive";
|
116
|
+
return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
|
117
|
+
winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
|
118
|
+
// winston.info("Request closed",updatedStatusRequest);
|
119
|
+
}).catch(function(err) {
|
120
|
+
if (process.env.HIDE_CLOSE_REQUEST_ERRORS == true || process.env.HIDE_CLOSE_REQUEST_ERRORS == "true" ) {
|
121
|
+
|
122
|
+
} else {
|
123
|
+
winston.error("CloseBotUnresponsiveRequestTask: Error closing the request with request_id: " + request.request_id, err);
|
124
|
+
}
|
125
|
+
|
126
|
+
})
|
127
|
+
}, delay)
|
112
128
|
|
113
129
|
});
|
114
130
|
|