@tiledesk/tiledesk-server 2.4.29 → 2.4.31

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.4.29",
4
+ "version": "2.4.31",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -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,33 @@ 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
- winston.debug("********unresponsive request ", request);
98
-
99
- // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
100
- const closed_by = "_bot_unresponsive";
101
- return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
102
- winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
103
- // winston.info("Request closed",updatedStatusRequest);
104
- }).catch(function(err) {
105
- if (process.env.HIDE_CLOSE_REQUEST_ERRORS == true || process.env.HIDE_CLOSE_REQUEST_ERRORS == "true" ) {
106
-
107
- } else {
108
- winston.error("CloseBotUnresponsiveRequestTask: Error closing the request with request_id: " + request.request_id, err);
109
- }
110
-
111
- })
103
+ let i = 0;
104
+ let delay = 0;
105
+ // winston.info("delay" + delay);
106
+
107
+ requests.forEach(request => {
108
+ i++;
109
+ delay = that.delayBeforeClosing*i;
110
+ setTimeout(function(){
111
+
112
+ // TODO aggiungi uno sleep
113
+ winston.debug("********unresponsive request ", request);
114
+
115
+ // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
116
+ const closed_by = "_bot_unresponsive";
117
+ return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
118
+ winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
119
+ // winston.info("Request closed",updatedStatusRequest);
120
+ }).catch(function(err) {
121
+ if (process.env.HIDE_CLOSE_REQUEST_ERRORS == true || process.env.HIDE_CLOSE_REQUEST_ERRORS == "true" ) {
122
+
123
+ } else {
124
+ winston.error("CloseBotUnresponsiveRequestTask: Error closing the request with request_id: " + request.request_id, err);
125
+ }
126
+
127
+ })
128
+ }, delay)
112
129
 
113
130
  });
114
131