@@ -8,6 +8,7 @@ import type { JobId } from '@server/lib/settings';
88import { getSettings } from '@server/lib/settings' ;
99import watchlistSync from '@server/lib/watchlistsync' ;
1010import logger from '@server/logger' ;
11+ import random from 'lodash/random' ;
1112import schedule from 'node-schedule' ;
1213
1314interface 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