diff options
Diffstat (limited to 'server/lib/worker/parent-process.ts')
-rw-r--r-- | server/lib/worker/parent-process.ts | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/server/lib/worker/parent-process.ts b/server/lib/worker/parent-process.ts index 4bc7f2620..7d4102047 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 { processImage } from '@server/helpers/image-utils' | 3 | import { processImage } from '@server/helpers/image-utils' |
4 | import { WORKER_THREADS } from '@server/initializers/constants' | 4 | import { WORKER_THREADS } from '@server/initializers/constants' |
5 | import { httpBroadcast } from './workers/http-broadcast' | ||
5 | import { downloadImage } from './workers/image-downloader' | 6 | import { downloadImage } from './workers/image-downloader' |
6 | 7 | ||
7 | let downloadImageWorker: Piscina | 8 | let downloadImageWorker: Piscina |
@@ -34,7 +35,41 @@ function processImageFromWorker (options: Parameters<typeof processImage>[0]): P | |||
34 | return processImageWorker.run(options) | 35 | return processImageWorker.run(options) |
35 | } | 36 | } |
36 | 37 | ||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | let parallelHTTPBroadcastWorker: Piscina | ||
41 | |||
42 | function parallelHTTPBroadcastFromWorker (options: Parameters<typeof httpBroadcast>[0]): Promise<ReturnType<typeof httpBroadcast>> { | ||
43 | if (!parallelHTTPBroadcastWorker) { | ||
44 | parallelHTTPBroadcastWorker = new Piscina({ | ||
45 | filename: join(__dirname, 'workers', 'http-broadcast.js'), | ||
46 | concurrentTasksPerWorker: WORKER_THREADS.PARALLEL_HTTP_BROADCAST.CONCURRENCY, | ||
47 | maxThreads: WORKER_THREADS.PARALLEL_HTTP_BROADCAST.MAX_THREADS | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | return parallelHTTPBroadcastWorker.run(options) | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | let sequentialHTTPBroadcastWorker: Piscina | ||
57 | |||
58 | function sequentialHTTPBroadcastFromWorker (options: Parameters<typeof httpBroadcast>[0]): Promise<ReturnType<typeof httpBroadcast>> { | ||
59 | if (!sequentialHTTPBroadcastWorker) { | ||
60 | sequentialHTTPBroadcastWorker = new Piscina({ | ||
61 | filename: join(__dirname, 'workers', 'http-broadcast.js'), | ||
62 | concurrentTasksPerWorker: WORKER_THREADS.SEQUENTIAL_HTTP_BROADCAST.CONCURRENCY, | ||
63 | maxThreads: WORKER_THREADS.SEQUENTIAL_HTTP_BROADCAST.MAX_THREADS | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | return sequentialHTTPBroadcastWorker.run(options) | ||
68 | } | ||
69 | |||
37 | export { | 70 | export { |
38 | downloadImageFromWorker, | 71 | downloadImageFromWorker, |
39 | processImageFromWorker | 72 | processImageFromWorker, |
73 | parallelHTTPBroadcastFromWorker, | ||
74 | sequentialHTTPBroadcastFromWorker | ||
40 | } | 75 | } |