-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean.js
More file actions
37 lines (27 loc) · 840 Bytes
/
clean.js
File metadata and controls
37 lines (27 loc) · 840 Bytes
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
var pg = require('pg');
var async = require('async');
var pool = new pg.Client(process.env.DATABASE_URL);
var client= undefined;
var timestamp = (+new Date());
timestamp -= 2*24*60*60*1000;
var calls = [];
calls.push(function (callback) {
pool.connect(function(err, _client, done) {
client = _client;
pool.query('DELETE FROM history WHERE timestamp < $1', [timestamp], function(err, result) {
if (err)
{ console.error(err); }
else
{ console.log('cleaned'); }
callback(null);
});
});
});
async.parallel(calls, function(err, result) {
/* this code will run after all calls finished the job or
when any of the calls passes an error */
if (err)
return console.log(err);
console.log('ended');
process.exit(0);
});