@@ -856,6 +856,7 @@ export function _runTaskList(
856
856
"Errors occurred whilst shutting down worker" ,
857
857
) ;
858
858
}
859
+
859
860
events . emit ( "pool:gracefulShutdown:complete" , {
860
861
pool : workerPool ,
861
862
workerPool,
@@ -870,9 +871,7 @@ export function _runTaskList(
870
871
const message = coerceError ( e ) . message ;
871
872
logger . error (
872
873
`Error occurred during graceful shutdown: ${ message } ` ,
873
- {
874
- error : e ,
875
- } ,
874
+ { error : e } ,
876
875
) ;
877
876
// NOTE: we now rely on forcefulShutdown to handle terminate()
878
877
if ( this . _forcefulShuttingDown ) {
@@ -922,6 +921,8 @@ export function _runTaskList(
922
921
// Stop new jobs being added
923
922
const deactivatePromise = deactivate ( ) ;
924
923
924
+ const errors : Error [ ] = [ ] ;
925
+
925
926
// Release all our workers' jobs
926
927
const workers = [ ...workerPool . _workers ] ;
927
928
const jobsInProgress : Array < Job > = workers
@@ -941,6 +942,7 @@ export function _runTaskList(
941
942
logger . error ( `Deactivation failed: ${ deactivateResult . reason } ` , {
942
943
error : deactivateResult . reason ,
943
944
} ) ;
945
+ errors . push ( coerceError ( deactivateResult . reason ) ) ;
944
946
}
945
947
946
948
if ( jobsInProgress . length > 0 ) {
@@ -954,19 +956,33 @@ export function _runTaskList(
954
956
workerIds,
955
957
} ,
956
958
) ;
957
- const cancelledJobs = await failJobs (
958
- compiledSharedOptions ,
959
- withPgClient ,
960
- workerPool . id ,
961
- jobsInProgress ,
962
- message ,
963
- ) ;
964
- logger . debug ( `Cancelled ${ cancelledJobs . length } jobs` , {
965
- cancelledJobs,
966
- } ) ;
959
+ try {
960
+ const cancelledJobs = await failJobs (
961
+ compiledSharedOptions ,
962
+ withPgClient ,
963
+ workerPool . id ,
964
+ jobsInProgress ,
965
+ message ,
966
+ ) ;
967
+ logger . debug ( `Cancelled ${ cancelledJobs . length } jobs` , {
968
+ cancelledJobs,
969
+ } ) ;
970
+ } catch ( e ) {
971
+ errors . push ( coerceError ( e ) ) ;
972
+ }
967
973
} else {
968
974
logger . debug ( "No active jobs to release" ) ;
969
975
}
976
+
977
+ if ( errors . length === 1 ) {
978
+ throw errors [ 0 ] ;
979
+ } else if ( errors . length > 1 ) {
980
+ throw new AggregateError (
981
+ errors ,
982
+ "Errors occurred whilst forcefully shutting down worker" ,
983
+ ) ;
984
+ }
985
+
970
986
events . emit ( "pool:forcefulShutdown:complete" , {
971
987
pool : workerPool ,
972
988
workerPool,
0 commit comments