fix: adjust the plex watchlist sync schedule to have fuzziness (#3502)

also fixes the schedule making it uneditable
pull/3497/head
Ryan Cohen 1 year ago committed by GitHub
parent c1a47bd9de
commit 2c3f533076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ import type { JobId } from '@server/lib/settings';
import { getSettings } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings';
import watchlistSync from '@server/lib/watchlistsync'; import watchlistSync from '@server/lib/watchlistsync';
import logger from '@server/logger'; import logger from '@server/logger';
import random from 'lodash/random';
import schedule from 'node-schedule'; import schedule from 'node-schedule';
interface ScheduledJob { interface ScheduledJob {
@ -60,21 +61,31 @@ export const startJobs = (): void => {
cancelFn: () => plexFullScanner.cancel(), cancelFn: () => plexFullScanner.cancel(),
}); });
// Run watchlist sync every 5 minutes // Watchlist Sync
scheduledJobs.push({ const watchlistSyncJob: ScheduledJob = {
id: 'plex-watchlist-sync', id: 'plex-watchlist-sync',
name: 'Plex Watchlist Sync', name: 'Plex Watchlist Sync',
type: 'process', type: 'process',
interval: 'minutes', interval: 'fixed',
cronSchedule: jobs['plex-watchlist-sync'].schedule, cronSchedule: jobs['plex-watchlist-sync'].schedule,
job: schedule.scheduleJob(jobs['plex-watchlist-sync'].schedule, () => { job: schedule.scheduleJob(new Date(Date.now() + 1000 * 60 * 20), () => {
logger.info('Starting scheduled job: Plex Watchlist Sync', { logger.info('Starting scheduled job: Plex Watchlist Sync', {
label: 'Jobs', label: 'Jobs',
}); });
watchlistSync.syncWatchlist(); watchlistSync.syncWatchlist();
}), }),
};
// To help alleviate load on Plex's servers, we will add some fuzziness to the next schedule
// after each run
watchlistSyncJob.job.on('run', () => {
watchlistSyncJob.job.schedule(
new Date(Math.floor(Date.now() + 1000 * 60 * random(14, 24, true)))
);
}); });
scheduledJobs.push(watchlistSyncJob);
// Run full radarr scan every 24 hours // Run full radarr scan every 24 hours
scheduledJobs.push({ scheduledJobs.push({
id: 'radarr-scan', id: 'radarr-scan',

Loading…
Cancel
Save