]>
Commit | Line | Data |
---|---|---|
2a491182 F |
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' | |
2a491182 F |
5 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' |
6 | import { synchronizeChannel } from '../sync-channel' | |
7 | import { AbstractScheduler } from './abstract-scheduler' | |
8 | ||
9 | export class VideoChannelSyncLatestScheduler extends AbstractScheduler { | |
10 | private static instance: AbstractScheduler | |
11 | protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHANNEL_SYNC_CHECK_INTERVAL | |
12 | ||
13 | private constructor () { | |
14 | super() | |
15 | } | |
16 | ||
17 | protected async internalExecute () { | |
2a491182 | 18 | if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) { |
910744fb | 19 | logger.debug('Discard channels synchronization as the feature is disabled') |
2a491182 F |
20 | return |
21 | } | |
22 | ||
910744fb C |
23 | logger.info('Checking channels to synchronize') |
24 | ||
2a491182 F |
25 | const channelSyncs = await VideoChannelSyncModel.listSyncs() |
26 | ||
27 | for (const sync of channelSyncs) { | |
28 | const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId) | |
29 | ||
97922ecf C |
30 | logger.info( |
31 | 'Creating video import jobs for "%s" sync with external channel "%s"', | |
32 | channel.Actor.preferredUsername, sync.externalChannelUrl | |
33 | ) | |
34 | ||
35 | const onlyAfter = sync.lastSyncAt || sync.createdAt | |
36 | ||
37 | await synchronizeChannel({ | |
38 | channel, | |
39 | externalChannelUrl: sync.externalChannelUrl, | |
40 | videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.VIDEOS_LIMIT_PER_SYNCHRONIZATION, | |
41 | channelSync: sync, | |
42 | onlyAfter | |
43 | }) | |
2a491182 F |
44 | } |
45 | } | |
46 | ||
47 | static get Instance () { | |
48 | return this.instance || (this.instance = new this()) | |
49 | } | |
50 | } |