forked from Illustrious-Dirigble/headcount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
35 lines (34 loc) · 1.3 KB
/
worker.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
/** Cron jobs in heroku (Heroku Scheduler)
* Creates an on/off dyno running a new instance of worker.js every day (midnight)
* The interval is decided in Heroku dashboard in Add-ons
* Command: "node worker.js" should tell heroku to run this file
* This worker contains one function that deletes events whose expiration date is in the past.
* The integer in the pgsql query specifies how many days we would like to extend it by if we need to.
* Query can also be done by requiring the user model, but the current_date in pgsql has been deprecated.
*/
function deleteOld() {
var knex = !process.env.DATABASE_URL ? require('./app/local_config.js') :
require('knex')({
client: 'pg',
connection: process.env.DATABASE_URL
});
// var User = require('./app/models/user.js');
knex.raw("delete from events where expiration < current_date + integer '0'")
// knex.select('*')
// .from('users')
.then(function(resp){
console.log('deleting',resp);
process.exit();
});
// new User()
// .query('where','created_at','<','current_date')
// .fetchAll()
// .then(function(collection) {
// console.log('fsdfds',collection.models);
// process.exit();
// })
// .catch(function(err){
// console.error(err);
// });
}
deleteOld();