-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJanitor.js
29 lines (26 loc) · 970 Bytes
/
Janitor.js
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
class Janitor {
/**
* @param {!PythonOnline} pythonOnline
* @param {number} compilationExpiration
* @param {number} cleanTimeout
*/
constructor(pythonOnline, compilationExpiration, cleanTimeout) {
this._pythonOnline = pythonOnline;
this._compilationExpiration = compilationExpiration;
this._cleanTimeout = cleanTimeout;
this._cleanup();
}
async _cleanup() {
var compilations = this._pythonOnline.compilations().filter(compilation => compilation.finished);
var currentTime = Date.now();
for (var compilation of compilations) {
var interval = currentTime - compilation.accessTime;
var expired = interval > this._compilationExpiration;
if (expired) {
this._pythonOnline.removeCompilation(compilation);
}
}
setTimeout(this._cleanup.bind(this), this._cleanTimeout);
}
}
module.exports = Janitor;