forked from vsp4/codechef-rating-predictor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.js
59 lines (51 loc) · 1.16 KB
/
process.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
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
var fs = require("fs");
var processLogFile = 'process.txt';
var isWorking = false;
module.exports = function (force)
{
if(force === undefined) {
force = false;
}
var processnow = false;
if (isWorking)
{
processnow = false;
}
else if (fs.existsSync(processLogFile))
{
var contents = fs.readFileSync(processLogFile, 'utf8');
var dt = new Date(contents);
if (dt == undefined)
{
processnow = true;
}
else
{
var seconds = (new Date() - dt)/1000;
if (seconds > 4*60 || force) //4 minutes
{
processnow = true;
}
}
}
else
{
processnow = true;
}
if (processnow)
{
var dt = new Date().toString();
fs.writeFileSync(processLogFile, dt);
console.log("Starting process", dt);
var status = require("./status.js");
var generator = require("./generate.js");
isWorking = true;
status(function()
{
generator(function()
{
isWorking = false;
})
});
}
}