-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cron job to remove old documents
- Loading branch information
1 parent
d92bb0f
commit 2ddc520
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,4 @@ [email protected] | |
[email protected] | ||
differential:vulcanize | ||
reactive-dict | ||
percolate:synced-cron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ [email protected] | |
[email protected] | ||
[email protected] | ||
percolate:[email protected] | ||
percolate:[email protected] | ||
[email protected] | ||
raix:[email protected] | ||
[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const collections = [ | ||
Actions, Attacks, Buffs, Classes, Effects, Experiences, | ||
Features, Notes, Proficiencies, SpellLists, Spells, | ||
Containers, Items, | ||
]; | ||
|
||
/** | ||
* Deletes all soft removed documents that were removed more than 30 minutes ago | ||
* and were not restored | ||
* @return {Number} Number of documents removed | ||
*/ | ||
const deleteOldSoftRemovedDocs = function(){ | ||
let numRemoved = 0; | ||
const now = new Date(); | ||
const thirtyMinutesAgo = new Date(now.getTime() - 30*60000); | ||
_.each(collections, (collection) => { | ||
numRemoved += collection.remove({ | ||
removed: true, | ||
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago | ||
}); | ||
}); | ||
return numRemoved; | ||
}; | ||
|
||
SyncedCron.add({ | ||
name: "Delete all soft removed items that haven't been restored", | ||
schedule: function(parser) { | ||
return parser.text('every 6 hours'); | ||
}, | ||
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(); | ||
} | ||
}, | ||
}); |