@@ -14,6 +14,7 @@ import {
14
14
FailJobFunction ,
15
15
GetJobFunction ,
16
16
Job ,
17
+ PromiseOrDirect ,
17
18
RunOnceOptions ,
18
19
TaskList ,
19
20
WorkerEventMap ,
@@ -709,6 +710,9 @@ export function _runTaskList(
709
710
// Make sure Node doesn't get upset about unhandled rejection
710
711
abortPromise . then ( null , ( ) => /* noop */ void 0 ) ;
711
712
713
+ let gracefulShutdownPromise : PromiseOrDirect < void > ;
714
+ let forcefulShutdownPromise : PromiseOrDirect < void > ;
715
+
712
716
// This is a representation of us that can be interacted with externally
713
717
const workerPool : WorkerPool = {
714
718
// "otpool" - "one time pool"
@@ -748,22 +752,17 @@ export function _runTaskList(
748
752
logger . error (
749
753
`gracefulShutdown called when forcefulShutdown is already in progress` ,
750
754
) ;
751
- return ;
755
+ return forcefulShutdownPromise ;
752
756
}
753
757
if ( workerPool . _shuttingDown ) {
754
758
logger . error (
755
759
`gracefulShutdown called when gracefulShutdown is already in progress` ,
756
760
) ;
757
- return ;
761
+ return gracefulShutdownPromise ;
758
762
}
759
- workerPool . _shuttingDown = true ;
760
-
761
- const abortTimer = setTimeout ( ( ) => {
762
- abortController . abort ( ) ;
763
- } , gracefulShutdownAbortTimeout ) ;
764
- abortTimer . unref ( ) ;
765
763
766
- return middleware . run (
764
+ workerPool . _shuttingDown = true ;
765
+ gracefulShutdownPromise = middleware . run (
767
766
"poolGracefulShutdown" ,
768
767
{ ctx : compiledSharedOptions , workerPool, message } ,
769
768
async ( { message } ) => {
@@ -872,6 +871,13 @@ export function _runTaskList(
872
871
}
873
872
} ,
874
873
) ;
874
+
875
+ const abortTimer = setTimeout ( ( ) => {
876
+ abortController . abort ( ) ;
877
+ } , gracefulShutdownAbortTimeout ) ;
878
+ abortTimer . unref ( ) ;
879
+
880
+ return gracefulShutdownPromise ;
875
881
} ,
876
882
877
883
/**
@@ -882,13 +888,14 @@ export function _runTaskList(
882
888
logger . error (
883
889
`forcefulShutdown called when forcefulShutdown is already in progress` ,
884
890
) ;
885
- return ;
891
+ return forcefulShutdownPromise ;
886
892
}
887
- return middleware . run (
893
+
894
+ workerPool . _forcefulShuttingDown = true ;
895
+ forcefulShutdownPromise = middleware . run (
888
896
"poolForcefulShutdown" ,
889
897
{ ctx : compiledSharedOptions , workerPool : this , message } ,
890
898
async ( { message } ) => {
891
- workerPool . _forcefulShuttingDown = true ;
892
899
events . emit ( "pool:forcefulShutdown" , {
893
900
pool : workerPool ,
894
901
workerPool,
@@ -970,6 +977,8 @@ export function _runTaskList(
970
977
}
971
978
} ,
972
979
) ;
980
+
981
+ return forcefulShutdownPromise ;
973
982
} ,
974
983
975
984
promise,
0 commit comments