diff options
Diffstat (limited to 'server/lib/worker/parent-process.ts')
-rw-r--r-- | server/lib/worker/parent-process.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/server/lib/worker/parent-process.ts b/server/lib/worker/parent-process.ts new file mode 100644 index 000000000..4bc7f2620 --- /dev/null +++ b/server/lib/worker/parent-process.ts | |||
@@ -0,0 +1,40 @@ | |||
1 | import { join } from 'path' | ||
2 | import Piscina from 'piscina' | ||
3 | import { processImage } from '@server/helpers/image-utils' | ||
4 | import { WORKER_THREADS } from '@server/initializers/constants' | ||
5 | import { downloadImage } from './workers/image-downloader' | ||
6 | |||
7 | let downloadImageWorker: Piscina | ||
8 | |||
9 | function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): Promise<ReturnType<typeof downloadImage>> { | ||
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) | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | let processImageWorker: Piscina | ||
24 | |||
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 | |||
34 | return processImageWorker.run(options) | ||
35 | } | ||
36 | |||
37 | export { | ||
38 | downloadImageFromWorker, | ||
39 | processImageFromWorker | ||
40 | } | ||