Skip to content

Commit

Permalink
remove instances older than two days
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaosthu committed Nov 29, 2016
1 parent 9462560 commit 7746519
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/db/client-instance-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint camelcase: "off" */
'use strict';

const logger = require('../logger');
const COLUMNS = ['app_name', 'instance_id', 'client_ip', 'last_seen', 'created_at'];
const TABLE = 'client_instances';

Expand All @@ -16,6 +17,15 @@ class ClientInstanceStore {

constructor (db) {
this.db = db;
setTimeout(() => this._removeInstancesOlderThanTwoDays(), 10).unref();
setInterval(() => this._removeInstancesOlderThanTwoDays(), 24 * 61 * 60 * 1000).unref();
}

_removeInstancesOlderThanTwoDays () {
this.db(TABLE)
.whereRaw('created_at < now() - interval \'2 days\'')
.del()
.then((res) => logger.info(`Deleted ${res} instances`));
}

updateRow (details) {
Expand Down

0 comments on commit 7746519

Please sign in to comment.