ActivityPub-federated video streaming platform using P2P directly in your web browser
Handle sync failure in synchronizeChannel fn
Chocobozzz97922ecf640e
diff --git a/server/lib/job-queue/handlers/video-channel-import.ts b/server/lib/job-queue/handlers/video-channel-import.tsindex 600292844b..c3dd8a6888 100644--- a/server/lib/job-queue/handlers/video-channel-import.ts+++ b/server/lib/job-queue/handlers/video-channel-import.ts@@ -5,7 +5,7 @@ import { synchronizeChannel } from '@server/lib/sync-channel'import { VideoChannelModel } from '@server/models/video/video-channel'import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'import { MChannelSync } from '@server/types/models'-import { VideoChannelImportPayload, VideoChannelSyncState } from '@shared/models'+import { VideoChannelImportPayload } from '@shared/models'export async function processVideoChannelImport (job: Job) {const payload = job.data as VideoChannelImportPayload@@ -32,17 +32,11 @@ export async function processVideoChannelImport (job: Job) {const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)- try {- logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)-- await synchronizeChannel({- channel: videoChannel,- externalChannelUrl: payload.externalChannelUrl,- channelSync- })- } catch (err) {- logger.error(`Failed to import channel ${videoChannel.name}`, { err })- channelSync.state = VideoChannelSyncState.FAILED- await channelSync.save()- }+ logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)++ await synchronizeChannel({+ channel: videoChannel,+ externalChannelUrl: payload.externalChannelUrl,+ channelSync+ })}diff --git a/server/lib/schedulers/video-channel-sync-latest-scheduler.ts b/server/lib/schedulers/video-channel-sync-latest-scheduler.tsindex a527f68b57..efb957fac0 100644--- a/server/lib/schedulers/video-channel-sync-latest-scheduler.ts+++ b/server/lib/schedulers/video-channel-sync-latest-scheduler.ts@@ -2,7 +2,6 @@ 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 { VideoChannelSyncState } from '@shared/models'import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'import { synchronizeChannel } from '../sync-channel'import { AbstractScheduler } from './abstract-scheduler'@@ -28,26 +27,20 @@ export class VideoChannelSyncLatestScheduler extends AbstractScheduler {for (const sync of channelSyncs) {const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)- try {- 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- })- } catch (err) {- logger.error(`Failed to synchronize channel ${channel.Actor.preferredUsername}`, { err })- sync.state = VideoChannelSyncState.FAILED- await sync.save()- }+ 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+ })}}diff --git a/server/lib/sync-channel.ts b/server/lib/sync-channel.tsindex f91599c14d..35af91429c 100644--- a/server/lib/sync-channel.ts+++ b/server/lib/sync-channel.ts@@ -24,56 +24,62 @@ export async function synchronizeChannel (options: {await channelSync.save()}- const user = await UserModel.loadByChannelActorId(channel.actorId)- const youtubeDL = new YoutubeDLWrapper(- externalChannelUrl,- ServerConfigManager.Instance.getEnabledResolutions('vod'),- CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION- )-- const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit })-- logger.info(- 'Fetched %d candidate URLs for sync channel %s.',- targetUrls.length, channel.Actor.preferredUsername, { targetUrls }- )-- if (targetUrls.length === 0) {- if (channelSync) {- channelSync.state = VideoChannelSyncState.SYNCED- await channelSync.save()- }-- return- }+ try {+ const user = await UserModel.loadByChannelActorId(channel.actorId)+ const youtubeDL = new YoutubeDLWrapper(+ externalChannelUrl,+ ServerConfigManager.Instance.getEnabledResolutions('vod'),+ CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION+ )- const children: CreateJobArgument[] = []+ const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit })- for (const targetUrl of targetUrls) {- if (await skipImport(channel, targetUrl, onlyAfter)) continue+ logger.info(+ 'Fetched %d candidate URLs for sync channel %s.',+ targetUrls.length, channel.Actor.preferredUsername, { targetUrls }+ )- const { job } = await buildYoutubeDLImport({- user,- channel,- targetUrl,- channelSync,- importDataOverride: {- privacy: VideoPrivacy.PUBLIC+ if (targetUrls.length === 0) {+ if (channelSync) {+ channelSync.state = VideoChannelSyncState.SYNCED+ await channelSync.save()}- })- children.push(job)- }+ return+ }++ const children: CreateJobArgument[] = []++ for (const targetUrl of targetUrls) {+ if (await skipImport(channel, targetUrl, onlyAfter)) continue- // Will update the channel sync status- const parent: CreateJobArgument = {- type: 'after-video-channel-import',- payload: {- channelSyncId: channelSync?.id+ const { job } = await buildYoutubeDLImport({+ user,+ channel,+ targetUrl,+ channelSync,+ importDataOverride: {+ privacy: VideoPrivacy.PUBLIC+ }+ })++ children.push(job)}- }- await JobQueue.Instance.createJobWithChildren(parent, children)+ // Will update the channel sync status+ const parent: CreateJobArgument = {+ type: 'after-video-channel-import',+ payload: {+ channelSyncId: channelSync?.id+ }+ }++ await JobQueue.Instance.createJobWithChildren(parent, children)+ } catch (err) {+ logger.error(`Failed to import channel ${channel.name}`, { err })+ channelSync.state = VideoChannelSyncState.FAILED+ await channelSync.save()+ }}// ---------------------------------------------------------------------------