2022-08-10 03:53:39 -04:00
|
|
|
import { logger } from '@server/helpers/logger'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
|
|
|
import { VideoChannelModel } from '@server/models/video/video-channel'
|
|
|
|
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
|
|
|
|
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
|
|
|
import { synchronizeChannel } from '../sync-channel'
|
|
|
|
import { AbstractScheduler } from './abstract-scheduler'
|
|
|
|
|
|
|
|
export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
|
|
|
|
private static instance: AbstractScheduler
|
|
|
|
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHANNEL_SYNC_CHECK_INTERVAL
|
|
|
|
|
|
|
|
private constructor () {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async internalExecute () {
|
|
|
|
if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
|
2022-09-14 09:10:37 -04:00
|
|
|
logger.debug('Discard channels synchronization as the feature is disabled')
|
2022-08-10 03:53:39 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-14 09:10:37 -04:00
|
|
|
logger.info('Checking channels to synchronize')
|
|
|
|
|
2022-08-10 03:53:39 -04:00
|
|
|
const channelSyncs = await VideoChannelSyncModel.listSyncs()
|
|
|
|
|
|
|
|
for (const sync of channelSyncs) {
|
|
|
|
const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)
|
|
|
|
|
2022-09-27 03:47:38 -04:00
|
|
|
logger.info(
|
|
|
|
'Creating video import jobs for "%s" sync with external channel "%s"',
|
|
|
|
channel.Actor.preferredUsername, sync.externalChannelUrl
|
|
|
|
)
|
|
|
|
|
|
|
|
const onlyAfter = sync.lastSyncAt || sync.createdAt
|
|
|
|
|
|
|
|
await synchronizeChannel({
|
|
|
|
channel,
|
|
|
|
externalChannelUrl: sync.externalChannelUrl,
|
|
|
|
videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.VIDEOS_LIMIT_PER_SYNCHRONIZATION,
|
|
|
|
channelSync: sync,
|
|
|
|
onlyAfter
|
|
|
|
})
|
2022-08-10 03:53:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static get Instance () {
|
|
|
|
return this.instance || (this.instance = new this())
|
|
|
|
}
|
|
|
|
}
|