mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 21:17:18 -04:00
add a scheduled notification cleanup job
This commit is contained in:
parent
4d066b1f30
commit
1e20e2601f
1 changed files with 36 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
import { SyncedCron } from 'meteor/percolate:synced-cron';
|
||||
|
||||
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
|
||||
// in the package definition.
|
||||
const isSandstorm =
|
||||
|
@ -926,6 +928,37 @@ if (Meteor.isServer) {
|
|||
});
|
||||
}
|
||||
|
||||
const addCronJob = _.debounce(
|
||||
Meteor.bindEnvironment(function notificationCleanupDebounced() {
|
||||
// passed in the removeAge has to be a number standing for the number of days after a notification is read before we remove it
|
||||
const envRemoveAge = process.env.NOTIFICATION_REMOVAL_AGE;
|
||||
// default notifications will be removed 2 days after they are read
|
||||
const defaultRemoveAge = 2;
|
||||
const removeAge = parseInt(envRemoveAge, 10) || defaultRemoveAge;
|
||||
|
||||
SyncedCron.add({
|
||||
name: 'notification_cleanup',
|
||||
schedule: parser => parser.text('every 1 days'),
|
||||
job: () => {
|
||||
for (const user of Users.find()) {
|
||||
for (const notification of user.profile.notifications) {
|
||||
if (notification.read) {
|
||||
const removeDate = new Date(notification.read);
|
||||
removeDate.setDate(removeDate.getDate() + removeAge);
|
||||
if (removeDate <= new Date()) {
|
||||
user.removeNotification(notification.activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
SyncedCron.start();
|
||||
}),
|
||||
500,
|
||||
);
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// Let mongoDB ensure username unicity
|
||||
Meteor.startup(() => {
|
||||
|
@ -939,6 +972,9 @@ if (Meteor.isServer) {
|
|||
},
|
||||
{ unique: true },
|
||||
);
|
||||
Meteor.defer(() => {
|
||||
addCronJob();
|
||||
});
|
||||
});
|
||||
|
||||
// OLD WAY THIS CODE DID WORK: When user is last admin of board,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue