1 import { Job } from 'bullmq'
2 import { logger } from '@server/helpers/logger'
3 import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
4 import { AfterVideoChannelImportPayload, VideoChannelSyncState, VideoImportPreventExceptionResult } from '@shared/models'
6 export async function processAfterVideoChannelImport (job: Job) {
7 const payload = job.data as AfterVideoChannelImportPayload
8 if (!payload.channelSyncId) return
10 logger.info('Processing after video channel import in job %s.', job.id)
12 const sync = await VideoChannelSyncModel.loadWithChannel(payload.channelSyncId)
14 logger.error('Unknown sync id %d.', payload.channelSyncId)
18 const childrenValues = await job.getChildrenValues<VideoImportPreventExceptionResult>()
23 for (const value of Object.values(childrenValues)) {
24 if (value.resultType === 'success') successes++
25 else if (value.resultType === 'error') errors++
29 sync.state = VideoChannelSyncState.FAILED
30 logger.error(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" with failures.`, { errors, successes })
32 sync.state = VideoChannelSyncState.SYNCED
33 logger.info(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" successfully.`, { successes })