feat: remove dep on cwd for workers (#20012)

This commit is contained in:
Min Idzelis
2025-07-18 10:57:49 -04:00
committed by GitHub
parent 493d85b021
commit 576f681b5c
2 changed files with 7 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import { CommandFactory } from 'nest-commander';
import { ChildProcess, fork } from 'node:child_process';
import { dirname, join } from 'node:path';
import { Worker } from 'node:worker_threads';
import { ImmichAdminModule } from 'src/app.module';
import { ImmichWorker, LogLevel } from 'src/enum';
@@ -33,14 +34,18 @@ const onExit = (name: string, exitCode: number | null) => {
function bootstrapWorker(name: ImmichWorker) {
console.log(`Starting ${name} worker`);
// eslint-disable-next-line unicorn/prefer-module
const basePath = dirname(__filename);
const workerFile = join(basePath, 'workers', `${name}.js`);
let worker: Worker | ChildProcess;
if (name === ImmichWorker.Api) {
worker = fork(`./dist/workers/${name}.js`, [], {
worker = fork(workerFile, [], {
execArgv: process.execArgv.map((arg) => (arg.startsWith('--inspect') ? '--inspect=0.0.0.0:9231' : arg)),
});
apiProcess = worker;
} else {
worker = new Worker(`./dist/workers/${name}.js`);
worker = new Worker(workerFile);
}
worker.on('error', (error) => onError(name, error));