-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics-tasks.js
32 lines (26 loc) · 1.03 KB
/
analytics-tasks.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
const sha512 = require("crypto-js/sha512")
const keys = require('./private/keys.json')
const MongoClient = require('mongodb').MongoClient;
const uri = `mongodb+srv://app:${keys.mongo.pass}@cluster0.zejsy.mongodb.net/analyticsDB?retryWrites=true&w=majority`;
const Agenda = require("agenda")
const moment = require("moment")
var uuid = require('uuid');
const agenda = new Agenda({ db: { address: uri, collection: 'sys-tasks' } });
agenda.define("clean ip cache", async (job) => {
console.log("cleaning ip cache", new Date().toTimeString())
let client = await MongoClient.connect(uri)
const ipCahce = client.db("analyticsDB").collection("ipCahce");
let res = await ipCahce.deleteMany({
timestamp: {
$lt: moment().subtract(1, 'hours').toISOString()
}
})
console.log(res.deletedCount, "deleted")
client.close()
});
(async function () {
// IIFE to give access to async/await
await agenda.start();
agenda.schedule("now", "clean ip cache")
await agenda.every("1 hours", "clean ip cache");
})();