Moved cron setup to startup
This commit is contained in:
@@ -1,43 +1,45 @@
|
|||||||
const collections = [
|
Meteor.startup(() => {
|
||||||
Actions, Attacks, Buffs, Classes, Effects, Experiences,
|
const collections = [
|
||||||
Features, Notes, Proficiencies, SpellLists, Spells,
|
Attacks, Buffs, Classes, Effects, Experiences,
|
||||||
Containers, Items,
|
Features, Notes, Proficiencies, SpellLists, Spells,
|
||||||
];
|
Containers, Items,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all soft removed documents that were removed more than 30 minutes ago
|
* Deletes all soft removed documents that were removed more than 30 minutes ago
|
||||||
* and were not restored
|
* and were not restored
|
||||||
* @return {Number} Number of documents removed
|
* @return {Number} Number of documents removed
|
||||||
*/
|
*/
|
||||||
const deleteOldSoftRemovedDocs = function(){
|
const deleteOldSoftRemovedDocs = function(){
|
||||||
let numRemoved = 0;
|
let numRemoved = 0;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const thirtyMinutesAgo = new Date(now.getTime() - 30*60000);
|
const thirtyMinutesAgo = new Date(now.getTime() - 30*60000);
|
||||||
_.each(collections, (collection) => {
|
_.each(collections, (collection) => {
|
||||||
numRemoved += collection.remove({
|
numRemoved += collection.remove({
|
||||||
removed: true,
|
removed: true,
|
||||||
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
|
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
return numRemoved;
|
||||||
return numRemoved;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
SyncedCron.add({
|
SyncedCron.add({
|
||||||
name: "Delete all soft removed items that haven't been restored",
|
name: "Delete all soft removed items that haven't been restored",
|
||||||
schedule: function(parser) {
|
schedule: function(parser) {
|
||||||
return parser.text('every 6 hours');
|
return parser.text('every 6 hours');
|
||||||
},
|
},
|
||||||
job: function() {
|
job: function() {
|
||||||
deleteOldSoftRemovedDocs();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add a method to manually trigger removal
|
|
||||||
Meteor.methods({
|
|
||||||
deleteOldSoftRemovedDocs() {
|
|
||||||
const user = Meteor.users.findOne(this.userId);
|
|
||||||
if (user && _.contains(user.roles, "admin")){
|
|
||||||
deleteOldSoftRemovedDocs();
|
deleteOldSoftRemovedDocs();
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
|
|
||||||
|
// Add a method to manually trigger removal
|
||||||
|
Meteor.methods({
|
||||||
|
deleteOldSoftRemovedDocs() {
|
||||||
|
const user = Meteor.users.findOne(this.userId);
|
||||||
|
if (user && _.contains(user.roles, "admin")){
|
||||||
|
deleteOldSoftRemovedDocs();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user