aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/worker/workers/http-broadcast.ts
blob: 8c9c6b8cab5f18c63d030f5e3445712deacd8a4c (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
28
29
30
31
32
import { map } from 'bluebird'
import { logger } from '@server/helpers/logger'
import { doRequest, PeerTubeRequestOptions } from '@server/helpers/requests'
import { BROADCAST_CONCURRENCY } from '@server/initializers/constants'

async function httpBroadcast (payload: {
  uris: string[]
  requestOptions: PeerTubeRequestOptions
}) {
  const { uris, requestOptions } = payload

  const badUrls: string[] = []
  const goodUrls: string[] = []

  await map(uris, async uri => {
    try {
      await doRequest(uri, requestOptions)
      goodUrls.push(uri)
    } catch (err) {
      logger.debug('HTTP broadcast to %s failed.', uri, { err })
      badUrls.push(uri)
    }
  }, { concurrency: BROADCAST_CONCURRENCY })

  return { goodUrls, badUrls }
}

module.exports = httpBroadcast

export {
  httpBroadcast
}