diff options
-rw-r--r-- | server/lib/worker/parent-process.ts | 32 |
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 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import Piscina from 'piscina' | 2 | import Piscina from 'piscina' |
3 | import { processImage } from '@server/helpers/image-utils' | ||
3 | import { WORKER_THREADS } from '@server/initializers/constants' | 4 | import { WORKER_THREADS } from '@server/initializers/constants' |
4 | import { downloadImage } from './workers/image-downloader' | 5 | import { downloadImage } from './workers/image-downloader' |
5 | import { processImage } from '@server/helpers/image-utils' | ||
6 | 6 | ||
7 | const downloadImagerWorker = new Piscina({ | 7 | let 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 | ||
13 | function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): Promise<ReturnType<typeof downloadImage>> { | 9 | function 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 | ||
19 | const processImageWorker = new Piscina({ | 23 | let 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 | ||
25 | function processImageFromWorker (options: Parameters<typeof processImage>[0]): Promise<ReturnType<typeof processImage>> { | 25 | function 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 | ||