aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/notify.ts
blob: 83605396c378b8af199a7503df61035e2e0e33a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Job } from 'bullmq'
import { Notifier } from '@server/lib/notifier'
import { VideoModel } from '@server/models/video/video'
import { NotifyPayload } from '@shared/models'
import { logger } from '../../../helpers/logger'

async function processNotify (job: Job) {
  const payload = job.data as NotifyPayload
  logger.info('Processing %s notification in job %s.', payload.action, job.id)

  if (payload.action === 'new-video') return doNotifyNewVideo(payload)
}

// ---------------------------------------------------------------------------

export {
  processNotify
}

// ---------------------------------------------------------------------------

async function doNotifyNewVideo (payload: NotifyPayload & { action: 'new-video' }) {
  const refreshedVideo = await VideoModel.loadFull(payload.videoUUID)
  if (!refreshedVideo) return

  Notifier.Instance.notifyOnNewVideoIfNeeded(refreshedVideo)
}