mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
scheduled posts: don't run update when not needed
This commit is contained in:
parent
336a1624eb
commit
b7bb9fd5f9
1 changed files with 6 additions and 6 deletions
|
@ -16,14 +16,14 @@ const addJob = function () {
|
|||
return parser.text('every 10 minutes');
|
||||
},
|
||||
job() {
|
||||
// fetch all posts tagged as scheduled
|
||||
// fetch all posts tagged as future
|
||||
const scheduledPosts = Posts.find({isFuture: true}, {fields: {_id: 1, status: 1, postedAt: 1, userId: 1, title: 1}}).fetch();
|
||||
|
||||
if (scheduledPosts) {
|
||||
// filter the scheduled posts to retrieve only the one that should update, considering their schedule
|
||||
const postsToUpdate = scheduledPosts.filter(post => post.postedAt <= new Date());
|
||||
|
||||
// update all posts with status approved
|
||||
// filter the scheduled posts to retrieve only the one that should update, considering their schedule
|
||||
const postsToUpdate = scheduledPosts.filter(post => post.postedAt <= new Date());
|
||||
|
||||
// update posts found
|
||||
if (!_.isEmpty(postsToUpdate)) {
|
||||
const postsIds = _.pluck(postsToUpdate, '_id');
|
||||
Posts.update({_id: {$in: postsIds}}, {$set: {isFuture: false}}, {multi: true});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue