aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/worker/parent-process.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-28 09:09:03 +0200
committerChocobozzz <me@florianbigard.com>2022-06-28 09:09:03 +0200
commitdaa0226b0a2ae1d19b342c2b7a54267d2fd8d30e (patch)
tree45324120f36d5acd31881b8cea0c39b94914d24e /server/lib/worker/parent-process.ts
parentccd62a45024d90c004d0d38737fef055b3fe22b7 (diff)
downloadPeerTube-daa0226b0a2ae1d19b342c2b7a54267d2fd8d30e.tar.gz
PeerTube-daa0226b0a2ae1d19b342c2b7a54267d2fd8d30e.tar.zst
PeerTube-daa0226b0a2ae1d19b342c2b7a54267d2fd8d30e.zip
Lazy load piscina
Diffstat (limited to 'server/lib/worker/parent-process.ts')
-rw-r--r--server/lib/worker/parent-process.ts32
1 files changed, 20 insertions, 12 deletions
diff --git a/server/lib/worker/parent-process.ts b/server/lib/worker/parent-process.ts
index 65300bbc8..4bc7f2620 100644
--- a/server/lib/worker/parent-process.ts
+++ b/server/lib/worker/parent-process.ts
@@ -1,28 +1,36 @@
1import { join } from 'path' 1import { join } from 'path'
2import Piscina from 'piscina' 2import Piscina from 'piscina'
3import { processImage } from '@server/helpers/image-utils'
3import { WORKER_THREADS } from '@server/initializers/constants' 4import { WORKER_THREADS } from '@server/initializers/constants'
4import { downloadImage } from './workers/image-downloader' 5import { downloadImage } from './workers/image-downloader'
5import { processImage } from '@server/helpers/image-utils'
6 6
7const downloadImagerWorker = new Piscina({ 7let downloadImageWorker: Piscina
8 filename: join(__dirname, 'workers', 'image-downloader.js'),
9 concurrentTasksPerWorker: WORKER_THREADS.DOWNLOAD_IMAGE.CONCURRENCY,
10 maxThreads: WORKER_THREADS.DOWNLOAD_IMAGE.MAX_THREADS
11})
12 8
13function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): Promise<ReturnType<typeof downloadImage>> { 9function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): Promise<ReturnType<typeof downloadImage>> {
14 return downloadImagerWorker.run(options) 10 if (!downloadImageWorker) {
11 downloadImageWorker = new Piscina({
12 filename: join(__dirname, 'workers', 'image-downloader.js'),
13 concurrentTasksPerWorker: WORKER_THREADS.DOWNLOAD_IMAGE.CONCURRENCY,
14 maxThreads: WORKER_THREADS.DOWNLOAD_IMAGE.MAX_THREADS
15 })
16 }
17
18 return downloadImageWorker.run(options)
15} 19}
16 20
17// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
18 22
19const processImageWorker = new Piscina({ 23let processImageWorker: Piscina
20 filename: join(__dirname, 'workers', 'image-processor.js'),
21 concurrentTasksPerWorker: WORKER_THREADS.PROCESS_IMAGE.CONCURRENCY,
22 maxThreads: WORKER_THREADS.PROCESS_IMAGE.MAX_THREADS
23})
24 24
25function processImageFromWorker (options: Parameters<typeof processImage>[0]): Promise<ReturnType<typeof processImage>> { 25function processImageFromWorker (options: Parameters<typeof processImage>[0]): Promise<ReturnType<typeof processImage>> {
26 if (!processImageWorker) {
27 processImageWorker = new Piscina({
28 filename: join(__dirname, 'workers', 'image-processor.js'),
29 concurrentTasksPerWorker: WORKER_THREADS.PROCESS_IMAGE.CONCURRENCY,
30 maxThreads: WORKER_THREADS.PROCESS_IMAGE.MAX_THREADS
31 })
32 }
33
26 return processImageWorker.run(options) 34 return processImageWorker.run(options)
27} 35}
28 36