-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession-checker.js
45 lines (37 loc) · 1.2 KB
/
session-checker.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
/**
* New node file
*/
var txHandler = require('./transaction-handler');
var cassandraBase = require('./cassandra-base');
var config = require('./config');
var logger = require('./logger');
var moment = require('moment');
var txInstance = txHandler.getInstance();
var formatt = 'YYYY-MM-DD HH:mm:ssZZ';
function clearOpenSessions(){
logger.info(undefined,'session clean started');
cassandraBase.getInstance().execute1("select * from tx_transactions",[],null,clearOpenSessionsCallback);
}
function clearOpenSessionsCallback(rows){
for(var i=0 ; i<rows.length ; i++){
var trx = rows[i];
var checkDate= moment().subtract(0,'minutes');
// var checkDate= moment().subtract(config.trxClearanceIntervalInMins,'minutes');
// var checkDateStr = checkDate.format(formatt)
var trx_start_date = moment(new Date(trx.start_date));
if (trx_start_date < checkDate){
txInstance.rollbackTransaction(trx.txid, function() {
},function(err) {
});
}
}
}
function updateCallback(){
logger.info("Session check finished.");
}
module.exports = {
schedule : function(){
// setInterval(clearOpenSessions,(50000));
setInterval(clearOpenSessions,(config.trxClearanceIntervalInMins * 60 * 1000));
}
}