The Digital Telepresence Platform core implementing user account management, authentication, search, global directory, and other platform-wide services. https://digitaltelepresence.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
1.3 KiB

// newsroom/cron/update-feeds.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const path = require('path');
const mongoose = require('mongoose');
const Feed = mongoose.model('Feed');
const { CronJob } = require('cron');
const { SiteWorkerProcess } = require(path.join(__dirname, '..', '..', '..', '..', 'lib', 'site-lib'));
class UpdateFeedsCron extends SiteWorkerProcess {
static get COMPONENT ( ) {
return {
name: 'updateFeeds',
slug: 'update-feeds-cron',
};
}
constructor (worker) {
super(worker, UpdateFeedsCron.COMPONENT);
}
async start ( ) {
await super.start();
await this.updateFeeds();
this.job = new CronJob(
'0 */15 * * * *',
this.updateFeeds.bind(this),
null,
true,
process.env.DTP_CRON_TIMEZONE || 'America/New_York',
);
}
async stop ( ) {
if (this.job) {
this.log.info('stopping feed update job');
this.job.stop();
delete this.job;
}
await super.stop();
}
async updateFeeds ( ) {
try {
await Feed
.find()
.lean()
.cursor()
.eachAsync(async (feed) => {
await this.worker.updateFeed(feed);
}, 4);
} catch (error) {
this.log.error('failed to update feeds', { error });
}
}
}
module.exports = UpdateFeedsCron;