1 import { logger } from '@server/helpers/logger'
2 import { CONFIG } from '@server/initializers/config'
3 import { VideoChannelModel } from '@server/models/video/video-channel'
4 import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
5 import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
6 import { synchronizeChannel } from '../sync-channel'
7 import { AbstractScheduler } from './abstract-scheduler'
9 export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
10 private static instance: AbstractScheduler
11 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHANNEL_SYNC_CHECK_INTERVAL
13 private constructor () {
17 protected async internalExecute () {
18 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
19 logger.debug('Discard channels synchronization as the feature is disabled')
23 logger.info('Checking channels to synchronize')
25 const channelSyncs = await VideoChannelSyncModel.listSyncs()
27 for (const sync of channelSyncs) {
28 const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)
31 'Creating video import jobs for "%s" sync with external channel "%s"',
32 channel.Actor.preferredUsername, sync.externalChannelUrl
35 const onlyAfter = sync.lastSyncAt || sync.createdAt
37 await synchronizeChannel({
39 externalChannelUrl: sync.externalChannelUrl,
40 videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.VIDEOS_LIMIT_PER_SYNCHRONIZATION,
47 static get Instance () {
48 return this.instance || (this.instance = new this())