From 3a54605d4e7ec5b4f47131e8d23255be35b7beac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Jun 2022 11:53:12 +0200 Subject: Process images in a dedicated worker --- server/lib/worker/parent-process.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'server/lib/worker/parent-process.ts') diff --git a/server/lib/worker/parent-process.ts b/server/lib/worker/parent-process.ts index 18dabd97f..188001677 100644 --- a/server/lib/worker/parent-process.ts +++ b/server/lib/worker/parent-process.ts @@ -2,6 +2,7 @@ import { join } from 'path' import Piscina from 'piscina' import { WORKER_THREADS } from '@server/initializers/constants' import { downloadImage } from './workers/image-downloader' +import { processImage } from '@server/helpers/image-utils' const downloadImagerWorker = new Piscina({ filename: join(__dirname, 'workers', 'image-downloader.js'), @@ -13,6 +14,19 @@ function downloadImageFromWorker (options: Parameters[0]): return downloadImagerWorker.run(options) } +// --------------------------------------------------------------------------- + +const processImageWorker = new Piscina({ + filename: join(__dirname, 'workers', 'image-processor.js'), + concurrentTasksPerWorker: WORKER_THREADS.DOWNLOAD_IMAGE.CONCURRENCY, + maxThreads: WORKER_THREADS.DOWNLOAD_IMAGE.MAX_THREADS +}) + +function processImageFromWorker (options: Parameters[0]): Promise> { + return processImageWorker.run(options) +} + export { - downloadImageFromWorker + downloadImageFromWorker, + processImageFromWorker } -- cgit v1.2.3