@@ -918,6 +918,8 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
918
918
this . events . on ( EventType . MIGRATING , boundPauseOnMigration ) ;
919
919
this . events . on ( EventType . ABORTING , boundPauseOnMigration ) ;
920
920
921
+ let stats = { } as FinalStatistics ;
922
+
921
923
try {
922
924
await this . autoscaledPool ! . run ( ) ;
923
925
} finally {
@@ -927,50 +929,51 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
927
929
process . off ( 'SIGINT' , sigintHandler ) ;
928
930
this . events . off ( EventType . MIGRATING , boundPauseOnMigration ) ;
929
931
this . events . off ( EventType . ABORTING , boundPauseOnMigration ) ;
930
- }
931
-
932
- const finalStats = this . stats . calculate ( ) ;
933
- const stats = {
934
- requestsFinished : this . stats . state . requestsFinished ,
935
- requestsFailed : this . stats . state . requestsFailed ,
936
- retryHistogram : this . stats . requestRetryHistogram ,
937
- ...finalStats ,
938
- } ;
939
- this . log . info ( 'Final request statistics:' , stats ) ;
940
932
941
- if ( this . stats . errorTracker . total !== 0 ) {
942
- const prettify = ( [ count , info ] : [ number , string [ ] ] ) => `${ count } x: ${ info . at ( - 1 ) ! . trim ( ) } (${ info [ 0 ] } )` ;
933
+ const finalStats = this . stats . calculate ( ) ;
934
+ stats = {
935
+ requestsFinished : this . stats . state . requestsFinished ,
936
+ requestsFailed : this . stats . state . requestsFailed ,
937
+ retryHistogram : this . stats . requestRetryHistogram ,
938
+ ...finalStats ,
939
+ } ;
940
+ this . log . info ( 'Final request statistics:' , stats ) ;
941
+
942
+ if ( this . stats . errorTracker . total !== 0 ) {
943
+ const prettify = ( [ count , info ] : [ number , string [ ] ] ) =>
944
+ `${ count } x: ${ info . at ( - 1 ) ! . trim ( ) } (${ info [ 0 ] } )` ;
945
+
946
+ this . log . info ( `Error analysis:` , {
947
+ totalErrors : this . stats . errorTracker . total ,
948
+ uniqueErrors : this . stats . errorTracker . getUniqueErrorCount ( ) ,
949
+ mostCommonErrors : this . stats . errorTracker . getMostPopularErrors ( 3 ) . map ( prettify ) ,
950
+ } ) ;
951
+ }
943
952
944
- this . log . info ( `Error analysis:` , {
945
- totalErrors : this . stats . errorTracker . total ,
946
- uniqueErrors : this . stats . errorTracker . getUniqueErrorCount ( ) ,
947
- mostCommonErrors : this . stats . errorTracker . getMostPopularErrors ( 3 ) . map ( prettify ) ,
948
- } ) ;
949
- }
953
+ const client = this . config . getStorageClient ( ) ;
950
954
951
- const client = this . config . getStorageClient ( ) ;
955
+ if ( client . teardown ) {
956
+ let finished = false ;
957
+ setTimeout ( ( ) => {
958
+ if ( ! finished ) {
959
+ this . log . info ( 'Waiting for the storage to write its state to file system.' ) ;
960
+ }
961
+ } , 1000 ) ;
962
+ await client . teardown ( ) ;
963
+ finished = true ;
964
+ }
952
965
953
- if ( client . teardown ) {
954
- let finished = false ;
955
- setTimeout ( ( ) => {
956
- if ( ! finished ) {
957
- this . log . info ( 'Waiting for the storage to write its state to file system.' ) ;
958
- }
959
- } , 1000 ) ;
960
- await client . teardown ( ) ;
961
- finished = true ;
966
+ periodicLogger . stop ( ) ;
967
+ await this . setStatusMessage (
968
+ `Finished! Total ${ this . stats . state . requestsFinished + this . stats . state . requestsFailed } requests: $ {
969
+ this . stats . state . requestsFinished
970
+ } succeeded, ${ this . stats . state . requestsFailed } failed.` ,
971
+ { isStatusMessageTerminal : true , level : 'INFO' } ,
972
+ ) ;
973
+ this . running = false ;
974
+ this . hasFinishedBefore = true ;
962
975
}
963
976
964
- periodicLogger . stop ( ) ;
965
- await this . setStatusMessage (
966
- `Finished! Total ${ this . stats . state . requestsFinished + this . stats . state . requestsFailed } requests: ${
967
- this . stats . state . requestsFinished
968
- } succeeded, ${ this . stats . state . requestsFailed } failed.`,
969
- { isStatusMessageTerminal : true , level : 'INFO' } ,
970
- ) ;
971
- this . running = false ;
972
- this . hasFinishedBefore = true ;
973
-
974
977
return stats ;
975
978
}
976
979
0 commit comments