@@ -12,29 +12,39 @@ if (immichApp) {
12
12
13
13
let apiProcess : ChildProcess | undefined ;
14
14
15
+ const onError = ( name : string , error : Error ) => {
16
+ console . error ( `${ name } worker error: ${ error } ` ) ;
17
+ } ;
18
+
19
+ const onExit = ( name : string , exitCode : number | null ) => {
20
+ if ( exitCode !== 0 ) {
21
+ console . error ( `${ name } worker exited with code ${ exitCode } ` ) ;
22
+
23
+ if ( apiProcess && name !== ImmichWorker . API ) {
24
+ console . error ( 'Killing api process' ) ;
25
+ apiProcess . kill ( 'SIGTERM' ) ;
26
+ apiProcess = undefined ;
27
+ }
28
+ }
29
+
30
+ process . exit ( exitCode ) ;
31
+ } ;
32
+
15
33
function bootstrapWorker ( name : ImmichWorker ) {
16
34
console . log ( `Starting ${ name } worker` ) ;
17
35
18
- const execArgv = process . execArgv . map ( ( arg ) => ( arg . startsWith ( '--inspect' ) ? '--inspect=0.0.0.0:9231' : arg ) ) ;
19
- const worker =
20
- name === ImmichWorker . API
21
- ? ( apiProcess = fork ( `./dist/workers/ ${ name } .js` , [ ] , { execArgv } ) )
22
- : new Worker ( `./dist/workers/ ${ name } .js` ) ;
23
-
24
- worker . on ( 'error' , ( error ) => {
25
- console . error ( ` ${ name } worker error: ${ error } `) ;
26
- } ) ;
36
+ let worker : Worker | ChildProcess ;
37
+ if ( name === ImmichWorker . API ) {
38
+ worker = fork ( `./dist/workers/ ${ name } .js` , [ ] , {
39
+ execArgv : process . execArgv . map ( ( arg ) => ( arg . startsWith ( '--inspect' ) ? '--inspect=0.0.0.0:9231' : arg ) ) ,
40
+ } ) ;
41
+ apiProcess = worker ;
42
+ } else {
43
+ worker = new Worker ( `./dist/workers/ ${ name } .js `) ;
44
+ }
27
45
28
- worker . on ( 'exit' , ( exitCode ) => {
29
- if ( exitCode !== 0 ) {
30
- console . error ( `${ name } worker exited with code ${ exitCode } ` ) ;
31
- if ( apiProcess && name !== ImmichWorker . API ) {
32
- console . error ( 'Killing api process' ) ;
33
- apiProcess . kill ( 'SIGTERM' ) ;
34
- }
35
- process . exit ( exitCode ) ;
36
- }
37
- } ) ;
46
+ worker . on ( 'error' , ( error ) => onError ( name , error ) ) ;
47
+ worker . on ( 'exit' , ( exitCode ) => onExit ( name , exitCode ) ) ;
38
48
}
39
49
40
50
function bootstrap ( ) {
0 commit comments