diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-27 11:53:12 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-27 11:53:12 +0200 |
commit | 3a54605d4e7ec5b4f47131e8d23255be35b7beac (patch) | |
tree | fce9d34812a7638d4a0253b076f05aabd15a2ce9 /server/lib/worker/parent-process.ts | |
parent | 88edc66edadcab1b0372679e23bf2a7a6ff50131 (diff) | |
download | PeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.tar.gz PeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.tar.zst PeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.zip |
Process images in a dedicated worker
Diffstat (limited to 'server/lib/worker/parent-process.ts')
-rw-r--r-- | server/lib/worker/parent-process.ts | 16 |
1 files changed, 15 insertions, 1 deletions
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' | |||
2 | import Piscina from 'piscina' | 2 | import Piscina from 'piscina' |
3 | import { WORKER_THREADS } from '@server/initializers/constants' | 3 | import { WORKER_THREADS } from '@server/initializers/constants' |
4 | import { downloadImage } from './workers/image-downloader' | 4 | import { downloadImage } from './workers/image-downloader' |
5 | import { processImage } from '@server/helpers/image-utils' | ||
5 | 6 | ||
6 | const downloadImagerWorker = new Piscina({ | 7 | const downloadImagerWorker = new Piscina({ |
7 | filename: join(__dirname, 'workers', 'image-downloader.js'), | 8 | filename: join(__dirname, 'workers', 'image-downloader.js'), |
@@ -13,6 +14,19 @@ function downloadImageFromWorker (options: Parameters<typeof downloadImage>[0]): | |||
13 | return downloadImagerWorker.run(options) | 14 | return downloadImagerWorker.run(options) |
14 | } | 15 | } |
15 | 16 | ||
17 | // --------------------------------------------------------------------------- | ||
18 | |||
19 | const processImageWorker = new Piscina({ | ||
20 | filename: join(__dirname, 'workers', 'image-processor.js'), | ||
21 | concurrentTasksPerWorker: WORKER_THREADS.DOWNLOAD_IMAGE.CONCURRENCY, | ||
22 | maxThreads: WORKER_THREADS.DOWNLOAD_IMAGE.MAX_THREADS | ||
23 | }) | ||
24 | |||
25 | function processImageFromWorker (options: Parameters<typeof processImage>[0]): Promise<ReturnType<typeof processImage>> { | ||
26 | return processImageWorker.run(options) | ||
27 | } | ||
28 | |||
16 | export { | 29 | export { |
17 | downloadImageFromWorker | 30 | downloadImageFromWorker, |
31 | processImageFromWorker | ||
18 | } | 32 | } |