]>
Commit | Line | Data |
---|---|---|
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' | |
5 | ||
6 | export async function processAfterVideoChannelImport (job: Job) { | |
7 | const payload = job.data as AfterVideoChannelImportPayload | |
8 | if (!payload.channelSyncId) return | |
9 | ||
10 | logger.info('Processing after video channel import in job %s.', job.id) | |
11 | ||
12 | const sync = await VideoChannelSyncModel.loadWithChannel(payload.channelSyncId) | |
13 | if (!sync) { | |
14 | logger.error('Unknown sync id %d.', payload.channelSyncId) | |
15 | return | |
16 | } | |
17 | ||
18 | const childrenValues = await job.getChildrenValues<VideoImportPreventExceptionResult>() | |
19 | ||
20 | let errors = 0 | |
21 | let successes = 0 | |
22 | ||
23 | for (const value of Object.values(childrenValues)) { | |
24 | if (value.resultType === 'success') successes++ | |
25 | else if (value.resultType === 'error') errors++ | |
26 | } | |
27 | ||
28 | if (errors > 0) { | |
29 | sync.state = VideoChannelSyncState.FAILED | |
30 | logger.error(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" with failures.`, { errors, successes }) | |
31 | } else { | |
32 | sync.state = VideoChannelSyncState.SYNCED | |
33 | logger.info(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" successfully.`, { successes }) | |
34 | } | |
35 | ||
36 | await sync.save() | |
37 | } |