News maintenance
With the current setup everything works as expected, except that we have the maintenance problem. The cron job here is adding the qualified news on each running cycle. But what happens to the old news? The rated-news object is the home for notification items and we need to implement a mechanism to loop through previous news items and throw them out if a specific condition is met.
To create this logic, inside the Notifier service add a new function to the scheduler as follows:
// src/app/Notifier/notifier.service.ts //... @Injectable() export class NotifierService { //... scheduler(notifier: string, threshold: string) { //... this.task = this.cron .schedule('*/15 * * * *', function () { self.removeOldNews(); self.collectRateNotify(notifier, threshold); }); } //... }
It is important to call the removeOldNews()
function before collecting any new items. Since the final list is assembled based on the current items under /rated...