Handle sync failure in synchronizeChannel fn
This commit is contained in:
parent
3097acc7c2
commit
97922ecf64
|
@ -5,7 +5,7 @@ import { synchronizeChannel } from '@server/lib/sync-channel'
|
||||||
import { VideoChannelModel } from '@server/models/video/video-channel'
|
import { VideoChannelModel } from '@server/models/video/video-channel'
|
||||||
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
|
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
|
||||||
import { MChannelSync } from '@server/types/models'
|
import { MChannelSync } from '@server/types/models'
|
||||||
import { VideoChannelImportPayload, VideoChannelSyncState } from '@shared/models'
|
import { VideoChannelImportPayload } from '@shared/models'
|
||||||
|
|
||||||
export async function processVideoChannelImport (job: Job) {
|
export async function processVideoChannelImport (job: Job) {
|
||||||
const payload = job.data as VideoChannelImportPayload
|
const payload = job.data as VideoChannelImportPayload
|
||||||
|
@ -32,17 +32,11 @@ export async function processVideoChannelImport (job: Job) {
|
||||||
|
|
||||||
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
|
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
|
||||||
|
|
||||||
try {
|
logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)
|
||||||
logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)
|
|
||||||
|
|
||||||
await synchronizeChannel({
|
await synchronizeChannel({
|
||||||
channel: videoChannel,
|
channel: videoChannel,
|
||||||
externalChannelUrl: payload.externalChannelUrl,
|
externalChannelUrl: payload.externalChannelUrl,
|
||||||
channelSync
|
channelSync
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
logger.error(`Failed to import channel ${videoChannel.name}`, { err })
|
|
||||||
channelSync.state = VideoChannelSyncState.FAILED
|
|
||||||
await channelSync.save()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { logger } from '@server/helpers/logger'
|
||||||
import { CONFIG } from '@server/initializers/config'
|
import { CONFIG } from '@server/initializers/config'
|
||||||
import { VideoChannelModel } from '@server/models/video/video-channel'
|
import { VideoChannelModel } from '@server/models/video/video-channel'
|
||||||
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
|
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
|
||||||
import { VideoChannelSyncState } from '@shared/models'
|
|
||||||
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
||||||
import { synchronizeChannel } from '../sync-channel'
|
import { synchronizeChannel } from '../sync-channel'
|
||||||
import { AbstractScheduler } from './abstract-scheduler'
|
import { AbstractScheduler } from './abstract-scheduler'
|
||||||
|
@ -28,26 +27,20 @@ export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
|
||||||
for (const sync of channelSyncs) {
|
for (const sync of channelSyncs) {
|
||||||
const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)
|
const channel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)
|
||||||
|
|
||||||
try {
|
logger.info(
|
||||||
logger.info(
|
'Creating video import jobs for "%s" sync with external channel "%s"',
|
||||||
'Creating video import jobs for "%s" sync with external channel "%s"',
|
channel.Actor.preferredUsername, sync.externalChannelUrl
|
||||||
channel.Actor.preferredUsername, sync.externalChannelUrl
|
)
|
||||||
)
|
|
||||||
|
|
||||||
const onlyAfter = sync.lastSyncAt || sync.createdAt
|
const onlyAfter = sync.lastSyncAt || sync.createdAt
|
||||||
|
|
||||||
await synchronizeChannel({
|
await synchronizeChannel({
|
||||||
channel,
|
channel,
|
||||||
externalChannelUrl: sync.externalChannelUrl,
|
externalChannelUrl: sync.externalChannelUrl,
|
||||||
videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.VIDEOS_LIMIT_PER_SYNCHRONIZATION,
|
videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.VIDEOS_LIMIT_PER_SYNCHRONIZATION,
|
||||||
channelSync: sync,
|
channelSync: sync,
|
||||||
onlyAfter
|
onlyAfter
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
logger.error(`Failed to synchronize channel ${channel.Actor.preferredUsername}`, { err })
|
|
||||||
sync.state = VideoChannelSyncState.FAILED
|
|
||||||
await sync.save()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,56 +24,62 @@ export async function synchronizeChannel (options: {
|
||||||
await channelSync.save()
|
await channelSync.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await UserModel.loadByChannelActorId(channel.actorId)
|
try {
|
||||||
const youtubeDL = new YoutubeDLWrapper(
|
const user = await UserModel.loadByChannelActorId(channel.actorId)
|
||||||
externalChannelUrl,
|
const youtubeDL = new YoutubeDLWrapper(
|
||||||
ServerConfigManager.Instance.getEnabledResolutions('vod'),
|
externalChannelUrl,
|
||||||
CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
|
ServerConfigManager.Instance.getEnabledResolutions('vod'),
|
||||||
)
|
CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
|
||||||
|
)
|
||||||
|
|
||||||
const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit })
|
const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit })
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
'Fetched %d candidate URLs for sync channel %s.',
|
'Fetched %d candidate URLs for sync channel %s.',
|
||||||
targetUrls.length, channel.Actor.preferredUsername, { targetUrls }
|
targetUrls.length, channel.Actor.preferredUsername, { targetUrls }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (targetUrls.length === 0) {
|
if (targetUrls.length === 0) {
|
||||||
if (channelSync) {
|
if (channelSync) {
|
||||||
channelSync.state = VideoChannelSyncState.SYNCED
|
channelSync.state = VideoChannelSyncState.SYNCED
|
||||||
await channelSync.save()
|
await channelSync.save()
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const children: CreateJobArgument[] = []
|
|
||||||
|
|
||||||
for (const targetUrl of targetUrls) {
|
|
||||||
if (await skipImport(channel, targetUrl, onlyAfter)) continue
|
|
||||||
|
|
||||||
const { job } = await buildYoutubeDLImport({
|
|
||||||
user,
|
|
||||||
channel,
|
|
||||||
targetUrl,
|
|
||||||
channelSync,
|
|
||||||
importDataOverride: {
|
|
||||||
privacy: VideoPrivacy.PUBLIC
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
children.push(job)
|
return
|
||||||
}
|
|
||||||
|
|
||||||
// Will update the channel sync status
|
|
||||||
const parent: CreateJobArgument = {
|
|
||||||
type: 'after-video-channel-import',
|
|
||||||
payload: {
|
|
||||||
channelSyncId: channelSync?.id
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await JobQueue.Instance.createJobWithChildren(parent, children)
|
const children: CreateJobArgument[] = []
|
||||||
|
|
||||||
|
for (const targetUrl of targetUrls) {
|
||||||
|
if (await skipImport(channel, targetUrl, onlyAfter)) continue
|
||||||
|
|
||||||
|
const { job } = await buildYoutubeDLImport({
|
||||||
|
user,
|
||||||
|
channel,
|
||||||
|
targetUrl,
|
||||||
|
channelSync,
|
||||||
|
importDataOverride: {
|
||||||
|
privacy: VideoPrivacy.PUBLIC
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
children.push(job)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue