Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit 2c3f533

Browse files
authored
fix: adjust the plex watchlist sync schedule to have fuzziness (#3502)
also fixes the schedule making it uneditable
1 parent c1a47bd commit 2c3f533

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

server/job/schedule.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { JobId } from '@server/lib/settings';
88
import { getSettings } from '@server/lib/settings';
99
import watchlistSync from '@server/lib/watchlistsync';
1010
import logger from '@server/logger';
11+
import random from 'lodash/random';
1112
import schedule from 'node-schedule';
1213

1314
interface ScheduledJob {
@@ -60,21 +61,31 @@ export const startJobs = (): void => {
6061
cancelFn: () => plexFullScanner.cancel(),
6162
});
6263

63-
// Run watchlist sync every 5 minutes
64-
scheduledJobs.push({
64+
// Watchlist Sync
65+
const watchlistSyncJob: ScheduledJob = {
6566
id: 'plex-watchlist-sync',
6667
name: 'Plex Watchlist Sync',
6768
type: 'process',
68-
interval: 'minutes',
69+
interval: 'fixed',
6970
cronSchedule: jobs['plex-watchlist-sync'].schedule,
70-
job: schedule.scheduleJob(jobs['plex-watchlist-sync'].schedule, () => {
71+
job: schedule.scheduleJob(new Date(Date.now() + 1000 * 60 * 20), () => {
7172
logger.info('Starting scheduled job: Plex Watchlist Sync', {
7273
label: 'Jobs',
7374
});
7475
watchlistSync.syncWatchlist();
7576
}),
77+
};
78+
79+
// To help alleviate load on Plex's servers, we will add some fuzziness to the next schedule
80+
// after each run
81+
watchlistSyncJob.job.on('run', () => {
82+
watchlistSyncJob.job.schedule(
83+
new Date(Math.floor(Date.now() + 1000 * 60 * random(14, 24, true)))
84+
);
7685
});
7786

87+
scheduledJobs.push(watchlistSyncJob);
88+
7889
// Run full radarr scan every 24 hours
7990
scheduledJobs.push({
8091
id: 'radarr-scan',

0 commit comments

Comments
 (0)