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