ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

51 lines
1.7 KiB

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