Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Improve schedulers first run

Chocobozzz71babda9925d
diff --git a/server/core/lib/schedulers/abstract-scheduler.ts b/server/core/lib/schedulers/abstract-scheduler.ts
index 9b9a03696f..2a857357a1 100644
--- a/server/core/lib/schedulers/abstract-scheduler.ts
+++ b/server/core/lib/schedulers/abstract-scheduler.ts
@@ -1,21 +1,57 @@
import Bluebird from 'bluebird'
-import { logger } from '../../helpers/logger.js'
+import { randomInt } from 'node:crypto'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
-export abstract class AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export abstract class AbstractScheduler {
protected abstract schedulerIntervalMs: number
private interval: NodeJS.Timeout
+ private firstRunTimeout: NodeJS.Timeout
private isRunning = false
+ private readonly randomRunOnEnable: boolean
+
+ constructor (options: {
+ randomRunOnEnable?: boolean
+ }) {
+ if (options?.randomRunOnEnable === true) {
+ this.randomRunOnEnable = true
+ }
+ }
+
enable () {
if (!this.schedulerIntervalMs) throw new Error('Interval is not correctly set.')
+ if (this.randomRunOnEnable === true) {
+ const randomDelay = randomInt(0, Math.floor(this.schedulerIntervalMs / 2))
+
+ this.firstRunTimeout = setTimeout(async () => {
+ try {
+ // execute() already handles errors
+ await this.execute()
+ } finally {
+ this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
+ }
+ }, randomDelay)
+
+ return
+ }
+
this.interval = setInterval(() => this.execute(), this.schedulerIntervalMs)
}
disable () {
- clearInterval(this.interval)
+ if (this.firstRunTimeout) {
+ clearTimeout(this.firstRunTimeout)
+ this.firstRunTimeout = undefined
+ }
+
+ if (this.interval) {
+ clearInterval(this.interval)
+ this.interval = undefined
+ }
}
async execute () {
@@ -25,7 +61,7 @@ export abstract class AbstractScheduler {
try {
await this.internalExecute()
} catch (err) {
- logger.error('Cannot execute %s scheduler.', this.constructor.name, { err })
+ logger.error('Cannot execute ' + this.constructor.name + ' scheduler.', { err, ...lTags() })
} finally {
this.isRunning = false
}
diff --git a/server/core/lib/schedulers/actor-follow-scheduler.ts b/server/core/lib/schedulers/actor-follow-scheduler.ts
index 86b83f60b0..9ca42f817b 100644
--- a/server/core/lib/schedulers/actor-follow-scheduler.ts
+++ b/server/core/lib/schedulers/actor-follow-scheduler.ts
@@ -1,21 +1,27 @@
-import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
-import { logger } from '../../helpers/logger.js'
+import { isProdInstance, isTestOrDevInstance } from '@peertube/peertube-node-utils'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
import { ACTOR_FOLLOW_SCORE, SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { ActorFollowModel } from '../../models/actor/actor-follow.js'
import { ActorFollowHealthCache } from '../actor-follow-health-cache.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class ActorFollowScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class ActorFollowScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
protected async internalExecute () {
+ // Run too often in test/dev instances
+ if (isProdInstance()) {
+ logger.info('Processing pending actor follow scores.', lTags())
+ }
+
await this.processPendingScores()
await this.removeBadActorFollows()
@@ -39,12 +45,12 @@ export class ActorFollowScheduler extends AbstractScheduler {
}
private async removeBadActorFollows () {
- if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).')
+ if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).', lTags())
try {
await ActorFollowModel.removeBadActorFollows()
} catch (err) {
- logger.error('Error in bad actor follows scheduler.', { err })
+ logger.error('Error in bad actor follows scheduler.', { err, ...lTags() })
}
}
diff --git a/server/core/lib/schedulers/auto-follow-index-instances.ts b/server/core/lib/schedulers/auto-follow-index-instances.ts
index 86678555d7..c8d982b903 100644
--- a/server/core/lib/schedulers/auto-follow-index-instances.ts
+++ b/server/core/lib/schedulers/auto-follow-index-instances.ts
@@ -3,13 +3,14 @@ import { JobQueue } from '@server/lib/job-queue/index.js'
import { ActorFollowModel } from '@server/models/actor/actor-follow.js'
import { getServerActor } from '@server/models/application/application.js'
import chunk from 'lodash-es/chunk.js'
-import { logger } from '../../helpers/logger.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS, SERVER_ACTOR_NAME } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class AutoFollowIndexInstances extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class AutoFollowIndexInstances extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES
@@ -17,7 +18,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
private lastCheck: Date
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected async internalExecute () {
@@ -29,7 +30,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
const indexUrl = CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
- logger.info('Auto follow instances of index %s.', indexUrl)
+ logger.info(`Auto follow instances of index ${indexUrl}`, lTags())
try {
const serverActor = await getServerActor()
@@ -41,7 +42,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
const { body } = await doJSONRequest<any>(indexUrl, { searchParams, preventSSRF: false })
if (!body.data || Array.isArray(body.data) === false) {
- logger.error('Cannot auto follow instances of index %s. Please check the auto follow URL.', indexUrl, { body })
+ logger.error(`Cannot auto follow instances of index ${indexUrl}. Please check the auto follow URL.`, { body, ...lTags() })
return
}
@@ -62,11 +63,9 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
JobQueue.Instance.createJobAsync({ type: 'activitypub-follow', payload })
}
}
-
} catch (err) {
- logger.error('Cannot auto follow hosts of index %s.', indexUrl, { err })
+ logger.error(`Cannot auto follow hosts of index ${indexUrl}.`, { err, ...lTags() })
}
-
}
static get Instance () {
diff --git a/server/core/lib/schedulers/geo-ip-update-scheduler.ts b/server/core/lib/schedulers/geo-ip-update-scheduler.ts
index a8d755e4ac..f55715f901 100644
--- a/server/core/lib/schedulers/geo-ip-update-scheduler.ts
+++ b/server/core/lib/schedulers/geo-ip-update-scheduler.ts
@@ -1,18 +1,22 @@
import { GeoIP } from '@server/helpers/geo-ip.js'
+import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class GeoIPUpdateScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class GeoIPUpdateScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.GEO_IP_UPDATE
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected internalExecute () {
+ logger.info('Running GeoIP update scheduler', lTags())
+
return GeoIP.Instance.updateDatabases()
}
diff --git a/server/core/lib/schedulers/peertube-version-check-scheduler.ts b/server/core/lib/schedulers/peertube-version-check-scheduler.ts
index 347bdbb381..5f2b4b8ce5 100644
--- a/server/core/lib/schedulers/peertube-version-check-scheduler.ts
+++ b/server/core/lib/schedulers/peertube-version-check-scheduler.ts
@@ -2,20 +2,21 @@ import { doJSONRequest } from '@server/helpers/requests.js'
import { ApplicationModel } from '@server/models/application/application.js'
import { compareSemVer } from '@peertube/peertube-core-utils'
import { JoinPeerTubeVersions } from '@peertube/peertube-models'
-import { logger } from '../../helpers/logger.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { PEERTUBE_VERSION, SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { Notifier } from '../notifier/index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected async internalExecute () {
@@ -25,12 +26,12 @@ export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
private async checkLatestVersion () {
if (CONFIG.PEERTUBE.CHECK_LATEST_VERSION.ENABLED === false) return
- logger.info('Checking latest PeerTube version.')
+ logger.info('Checking latest PeerTube version.', lTags())
const { body } = await doJSONRequest<JoinPeerTubeVersions>(CONFIG.PEERTUBE.CHECK_LATEST_VERSION.URL, { preventSSRF: false })
if (!body?.peertube?.latestVersion) {
- logger.warn('Cannot check latest PeerTube version: body is invalid.', { body })
+ logger.warn('Cannot check latest PeerTube version: body is invalid.', { body, ...lTags() })
return
}
diff --git a/server/core/lib/schedulers/plugins-check-scheduler.ts b/server/core/lib/schedulers/plugins-check-scheduler.ts
index 627289663d..7513a0e4b8 100644
--- a/server/core/lib/schedulers/plugins-check-scheduler.ts
+++ b/server/core/lib/schedulers/plugins-check-scheduler.ts
@@ -1,6 +1,6 @@
import { compareSemVer } from '@peertube/peertube-core-utils'
import chunk from 'lodash-es/chunk.js'
-import { logger } from '../../helpers/logger.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { PluginModel } from '../../models/server/plugin.js'
@@ -8,14 +8,15 @@ import { Notifier } from '../notifier/index.js'
import { getLatestPluginsVersion } from '../plugins/plugin-index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class PluginsCheckScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class PluginsCheckScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHECK_PLUGINS
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected async internalExecute () {
@@ -25,7 +26,7 @@ export class PluginsCheckScheduler extends AbstractScheduler {
private async checkLatestPluginsVersion () {
if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
- logger.info('Checking latest plugins version.')
+ logger.info('Checking latest plugins version.', lTags())
const plugins = await PluginModel.listInstalled()
@@ -59,11 +60,11 @@ export class PluginsCheckScheduler extends AbstractScheduler {
Notifier.Instance.notifyOfNewPluginVersion(plugin)
}
- logger.info('Plugin %s has a new latest version %s.', result.npmName, plugin.latestVersion)
+ logger.info(`Plugin ${result.npmName} has a new latest version ${plugin.latestVersion}`, lTags())
}
}
} catch (err) {
- logger.error('Cannot get latest plugins version.', { npmNames, err })
+ logger.error('Cannot get latest plugins version.', { npmNames, err, ...lTags() })
}
}
}
diff --git a/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts b/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
index ea626cc31b..b7a113dcd4 100644
--- a/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
+++ b/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
@@ -3,23 +3,22 @@ import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
import { uploadx } from '../uploadx.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('scheduler', 'resumable-upload', 'cleaner')
+const lTags = loggerTagsFactory('schedulers', 'resumable-upload', 'cleaner')
export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler {
-
private static instance: AbstractScheduler
private lastExecutionTimeMs: number
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
this.lastExecutionTimeMs = new Date().getTime()
}
protected async internalExecute () {
- logger.debug('Removing dangling resumable uploads', lTags())
+ logger.info('Removing dangling resumable uploads', lTags())
const now = new Date().getTime()
diff --git a/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts b/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
index bf3a752f23..3501566687 100644
--- a/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
+++ b/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
@@ -1,24 +1,27 @@
-import { logger } from '../../helpers/logger.js'
-import { AbstractScheduler } from './abstract-scheduler.js'
-import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
-import { CONFIG } from '../../initializers/config.js'
import { UserExportModel } from '@server/models/user/user-export.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { CONFIG } from '../../initializers/config.js'
+import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
+import { AbstractScheduler } from './abstract-scheduler.js'
-export class RemoveExpiredUserExportsScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class RemoveExpiredUserExportsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_EXPIRED_USER_EXPORTS
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
protected async internalExecute () {
+ logger.info('Running expired user exports checker.', lTags())
+
const expired = await UserExportModel.listExpired(CONFIG.EXPORT.USERS.EXPORT_EXPIRATION)
for (const userExport of expired) {
- logger.info('Removing expired user exports ' + userExport.filename)
+ logger.info(`Removing expired user exports ${userExport.filename}`, lTags())
await userExport.destroy()
}
diff --git a/server/core/lib/schedulers/remove-old-history-scheduler.ts b/server/core/lib/schedulers/remove-old-history-scheduler.ts
index 3a557ae97a..7f547503e8 100644
--- a/server/core/lib/schedulers/remove-old-history-scheduler.ts
+++ b/server/core/lib/schedulers/remove-old-history-scheduler.ts
@@ -1,23 +1,24 @@
-import { logger } from '../../helpers/logger.js'
-import { AbstractScheduler } from './abstract-scheduler.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { UserVideoHistoryModel } from '../../models/user/user-video-history.js'
-import { CONFIG } from '../../initializers/config.js'
+import { AbstractScheduler } from './abstract-scheduler.js'
-export class RemoveOldHistoryScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers')
+export class RemoveOldHistoryScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected internalExecute () {
if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
- logger.info('Removing old videos history.')
+ logger.info('Removing old videos history.', lTags())
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
diff --git a/server/core/lib/schedulers/remove-old-views-scheduler.ts b/server/core/lib/schedulers/remove-old-views-scheduler.ts
index 039354db47..3c5a9329c8 100644
--- a/server/core/lib/schedulers/remove-old-views-scheduler.ts
+++ b/server/core/lib/schedulers/remove-old-views-scheduler.ts
@@ -1,17 +1,19 @@
import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer.js'
import { VideoViewModel } from '@server/models/view/video-view.js'
-import { logger } from '../../helpers/logger.js'
+import { logger, loggerTagsFactory } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
+const lTags = loggerTagsFactory('schedulers')
+
export class RemoveOldViewsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected async internalExecute () {
@@ -22,7 +24,7 @@ export class RemoveOldViewsScheduler extends AbstractScheduler {
private removeRemoteViews () {
if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE <= 0) return
- logger.info('Removing old views from remote videos.')
+ logger.info('Removing old views from remote videos.', lTags())
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
@@ -33,7 +35,7 @@ export class RemoveOldViewsScheduler extends AbstractScheduler {
private async removeLocalViews () {
if (CONFIG.VIEWS.VIDEOS.LOCAL.MAX_AGE <= 0) return
- logger.info('Removing old views from local videos.')
+ logger.info('Removing old views from local videos.', lTags())
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.LOCAL.MAX_AGE).toISOString()
diff --git a/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts b/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
index f02615b1b1..0c36ecdedf 100644
--- a/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
+++ b/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
@@ -5,7 +5,7 @@ import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { getRunnerJobHandlerClass } from '../runners/index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('runner')
+const lTags = loggerTagsFactory('schedulers', 'runner')
export class RunnerJobWatchDogScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -13,7 +13,7 @@ export class RunnerJobWatchDogScheduler extends AbstractScheduler {
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.RUNNER_JOB_WATCH_DOG
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
protected async internalExecute () {
diff --git a/server/core/lib/schedulers/update-token-session-scheduler.ts b/server/core/lib/schedulers/update-token-session-scheduler.ts
index 67826617f4..e488a9a5b2 100644
--- a/server/core/lib/schedulers/update-token-session-scheduler.ts
+++ b/server/core/lib/schedulers/update-token-session-scheduler.ts
@@ -1,6 +1,10 @@
+import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { OAuthTokenModel } from '@server/models/oauth/oauth-token.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
+import { isProdInstance } from '@peertube/peertube-node-utils'
+
+const lTags = loggerTagsFactory('schedulers')
type UpdatePayload = {
lastActivityDate: Date
@@ -16,7 +20,7 @@ export class UpdateTokenSessionScheduler extends AbstractScheduler {
private toUpdate = new Map<number, UpdatePayload>()
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
addToUpdate (id: number, payload: UpdatePayload) {
@@ -24,6 +28,9 @@ export class UpdateTokenSessionScheduler extends AbstractScheduler {
}
protected async internalExecute () {
+ // Log only on production instances to reduce noise on development/test instances
+ if (isProdInstance()) logger.debug('Running update token session scheduler', lTags())
+
const entriesToUpdate = this.toUpdate.entries()
this.toUpdate = new Map()
diff --git a/server/core/lib/schedulers/update-videos-scheduler.ts b/server/core/lib/schedulers/update-videos-scheduler.ts
index 457ccc8ea6..d35dd96808 100644
--- a/server/core/lib/schedulers/update-videos-scheduler.ts
+++ b/server/core/lib/schedulers/update-videos-scheduler.ts
@@ -12,7 +12,7 @@ import { VideoPathManager } from '../video-path-manager.js'
import { setVideoPrivacy } from '../video-privacy.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('update-videos-scheduler')
+const lTags = loggerTagsFactory('schedulers', 'update-videos')
export class UpdateVideosScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -20,7 +20,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
protected async internalExecute () {
@@ -28,6 +28,8 @@ export class UpdateVideosScheduler extends AbstractScheduler {
}
private async updateVideos () {
+ logger.debug('Running update videos scheduler', lTags())
+
if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined
const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate()
@@ -59,7 +61,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
const video = await VideoModel.loadFull(schedule.videoId, t)
if (video.state === VideoState.TO_TRANSCODE) return null
- logger.info('Executing scheduled video update on %s.', video.uuid)
+ logger.info('Executing scheduled video update on ' + video.uuid, lTags(video.uuid))
if (schedule.privacy) {
isNewVideoForFederation = isNewVideoPrivacyForFederation(video.privacy, schedule.privacy)
diff --git a/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts b/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
index d49b80ffc8..36ca2321a8 100644
--- a/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
+++ b/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
@@ -1,21 +1,21 @@
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
-import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.js'
+import { VideoChannelModel } from '@server/models/video/video-channel.js'
+import { VideoImportModel } from '@server/models/video/video-import.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { synchronizeChannel } from '../sync-channel.js'
-import { AbstractScheduler } from './abstract-scheduler.js'
-import { VideoImportModel } from '@server/models/video/video-import.js'
import { retryImport } from '../video-post-import.js'
+import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('channel-synchronization')
+const lTags = loggerTagsFactory('schedulers', 'channel-synchronization')
export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHANNEL_SYNC_CHECK_INTERVAL
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected async internalExecute () {
diff --git a/server/core/lib/schedulers/video-views-buffer-scheduler.ts b/server/core/lib/schedulers/video-views-buffer-scheduler.ts
index fd8a61324c..4d1c7f0053 100644
--- a/server/core/lib/schedulers/video-views-buffer-scheduler.ts
+++ b/server/core/lib/schedulers/video-views-buffer-scheduler.ts
@@ -5,19 +5,20 @@ import { federateVideoIfNeeded } from '../activitypub/videos/index.js'
import { Redis } from '../redis.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('views')
+const lTags = loggerTagsFactory('schedulers', 'views')
export class VideoViewsBufferScheduler extends AbstractScheduler {
-
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.VIDEO_VIEWS_BUFFER_UPDATE
private constructor () {
- super()
+ super({ randomRunOnEnable: false })
}
protected async internalExecute () {
+ logger.debug('Running video views buffer scheduler', lTags())
+
const videoIds = await Redis.Instance.listLocalVideosViewed()
if (videoIds.length === 0) return
diff --git a/server/core/lib/schedulers/videos-redundancy-scheduler.ts b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
index 077bbf7abb..4d988560d5 100644
--- a/server/core/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
@@ -22,7 +22,7 @@ import { removeVideoRedundancy } from '../redundancy.js'
import { generateHLSRedundancyUrl } from '../video-urls.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('redundancy')
+const lTags = loggerTagsFactory('schedulers', 'redundancy')
type CandidateToDuplicate = {
redundancy: VideosRedundancyStrategy
@@ -31,13 +31,12 @@ type CandidateToDuplicate = {
}
export class VideosRedundancyScheduler extends AbstractScheduler {
-
private static instance: VideosRedundancyScheduler
protected schedulerIntervalMs = CONFIG.REDUNDANCY.VIDEOS.CHECK_INTERVAL
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
async createManualRedundancy (videoId: number) {
@@ -79,7 +78,9 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
logger.info(
'Will duplicate video %s in redundancy scheduler "%s".',
- videoToDuplicate.url, redundancyConfig.strategy, lTags(videoToDuplicate.uuid)
+ videoToDuplicate.url,
+ redundancyConfig.strategy,
+ lTags(videoToDuplicate.uuid)
)
await this.createVideoRedundancies(candidateToDuplicate)
@@ -108,7 +109,8 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
if (!redundancyConfig) {
logger.info(
'Destroying redundancy %s because the redundancy %s does not exist anymore.',
- redundancyModel.url, redundancyModel.strategy
+ redundancyModel.url,
+ redundancyModel.strategy
)
await removeVideoRedundancy(redundancyModel)
@@ -129,7 +131,8 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
} catch (err) {
logger.error(
'Cannot extend or remove expiration of %s video from our redundancy system.',
- this.buildEntryLogId(redundancyModel), { err, ...lTags(redundancyModel.getVideoUUID()) }
+ this.buildEntryLogId(redundancyModel),
+ { err, ...lTags(redundancyModel.getVideoUUID()) }
)
}
}
@@ -155,7 +158,8 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
} catch (err) {
logger.error(
'Cannot remove redundancy %s from our redundancy system.',
- this.buildEntryLogId(redundancyModel), lTags(redundancyModel.getVideoUUID())
+ this.buildEntryLogId(redundancyModel),
+ lTags(redundancyModel.getVideoUUID())
)
}
}
diff --git a/server/core/lib/schedulers/youtube-dl-update-scheduler.ts b/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
index 9e3cbf7b2c..30a21ceffe 100644
--- a/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
+++ b/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
@@ -1,18 +1,22 @@
+import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { YoutubeDLCLI } from '@server/helpers/youtube-dl/index.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-export class YoutubeDlUpdateScheduler extends AbstractScheduler {
+const lTags = loggerTagsFactory('schedulers', 'youtube-dl')
+export class YoutubeDlUpdateScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.YOUTUBE_DL_UPDATE
private constructor () {
- super()
+ super({ randomRunOnEnable: true })
}
protected internalExecute () {
+ logger.info('Running youtube-dl updated scheduler', lTags())
+
return YoutubeDLCLI.updateYoutubeDLBinary()
}