-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule.js
More file actions
62 lines (57 loc) · 1.52 KB
/
Copy pathschedule.js
File metadata and controls
62 lines (57 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class RequestCfgData {
constructor(id, ip, dir, isAbsP, haveRfile, cHour) {
this.id = id;
this.ip = ip;
this.dir = dir;
this.isAbsP = isAbsP;
this.haveRfile = haveRfile;
this.cHour = cHour;
this.instFile = "";
this.hourFile = "";
this.dayFile = "";
this.statFile = "";
}
}
class UpdateScheduleLine {
constructor( id ) {
this.id = id;
this.instFile;
this.hourFile;
this.dayFile;
this.statFile;
}
}
class UpdateSchedule {
constructor( timeoutC, timeoutH, timeoutD, timeoutS ) {
this.timeouts = {};
this.timeouts.currInst = timeoutC;
this.timeouts.lastHour = timeoutH;
this.timeouts.lastDay = timeoutD;
this.timeouts.currStat = timeoutS;
this.lines = [];
}
update(id, prop, value){
let el = this.lines.find(l=>l.id === id);
if (!el) {
el = new UpdateScheduleLine( id );
el[prop] = value;
this.lines.push(el);
}
el[prop] = value;
}
needUpdate(id, prop){
let el = this.lines.find(l=>l.id === id);
if (el) {
//null or undefined не обновилось ни разу
if (!el[prop]) return true;
//
let dt = Date.now() - el[prop];
return (dt > this.timeouts[prop]*1000) ? true : false;
}
//строка не найдена - нужно обновить
return true;
}
}
module.exports = {
UpdateSchedule : UpdateSchedule,
}