Skip to content

Commit

Permalink
fix: adjust the plex watchlist sync schedule to have fuzziness (#3502)
Browse files Browse the repository at this point in the history
also fixes the schedule making it uneditable
  • Loading branch information
sct authored Jun 13, 2023
1 parent c1a47bd commit 2c3f533
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions server/job/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { JobId } from '@server/lib/settings';
import { getSettings } from '@server/lib/settings';
import watchlistSync from '@server/lib/watchlistsync';
import logger from '@server/logger';
import random from 'lodash/random';
import schedule from 'node-schedule';

interface ScheduledJob {
Expand Down Expand Up @@ -60,21 +61,31 @@ export const startJobs = (): void => {
cancelFn: () => plexFullScanner.cancel(),
});

// Run watchlist sync every 5 minutes
scheduledJobs.push({
// Watchlist Sync
const watchlistSyncJob: ScheduledJob = {
id: 'plex-watchlist-sync',
name: 'Plex Watchlist Sync',
type: 'process',
interval: 'minutes',
interval: 'fixed',
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', {
label: 'Jobs',
});
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
scheduledJobs.push({
id: 'radarr-scan',
Expand Down

0 comments on commit 2c3f533

Please sign in to comment.