aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/worker/parent-process.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/worker/parent-process.ts')
-rw-r--r--server/lib/worker/parent-process.ts40
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 @@
1import { join } from 'path'
2import Piscina from 'piscina'
3import { processImage } from '@server/helpers/image-utils'
4import { WORKER_THREADS } from '@server/initializers/constants'
5import { downloadImage } from './workers/image-downloader'
6
7let downloadImageWorker: Piscina
8
9function 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
23let processImageWorker: Piscina
24
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
34 return processImageWorker.run(options)
35}
36
37export {
38 downloadImageFromWorker,
39 processImageFromWorker
40}