-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
35 lines (35 loc) · 1.28 KB
/
Jakefile
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
var end = function () {
process.exit();
}
namespace('bnb', function () {
desc('Check for inactive devices');
task('inactive', function () {
var Mycro = require('mycro'),
mycro = new Mycro({hooks: ['server', 'connections', 'models', 'services']}),
fs = require('fs'),
yaml = require('js-yaml'),
params = yaml.safeLoad(fs.readFileSync('config/parameters.yml', 'utf8'));
mycro.start(function (err) {
var device = mycro.models['device'];
device.update(
{active: false},
{
where: {
last_heartbeat: {
$or: [
{$lt: device.sequelize.fn('date_sub', device.sequelize.fn('NOW'), device.sequelize.literal('INTERVAL ' + params['max_heartbeat'] + ' MINUTE'))},
null
]
}
}
}
).spread(function (affectedCount, affectedRows) {
console.log('Marked', affectedCount, 'devices as inactive');
end();
}).catch(function (err) {
console.log(err);
end();
});
});
});
});