aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/worker/parent-process.ts
blob: 18dabd97f5a483ecf641e5d6b8d2840691c60c4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { join } from 'path'
import Piscina from 'piscina'
import { WORKER_THREADS } from '@server/initializers/constants'
import { downloadImage } from './workers/image-downloader'

const downloadImagerWorker = new Piscina({
  filename: join(__dirname, 'workers', 'image-downloader.js'),
  concurrentTasksPerWorker: WORKER_THREADS.DOWNLOAD_IMAGE.CONCURRENCY,
  maxThreads: WORKER_THREADS.DOWNLOAD_IMAGE.MAX_THREADS
})

function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): Promise<ReturnType<typeof downloadImage>> {
  return downloadImagerWorker.run(options)
}

export {
  downloadImageFromWorker
}