aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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