@@ -8,6 +8,7 @@ import { betterClearInterval, betterSetInterval } from '@apify/utilities';
88import { Configuration } from '../configuration' ;
99import { CriticalError } from '../errors' ;
1010import { log as defaultLog } from '../log' ;
11+ import type { LoadSignal } from './load_signal' ;
1112import type { SnapshotterOptions } from './snapshotter' ;
1213import { Snapshotter } from './snapshotter' ;
1314import type { SystemInfo , SystemStatusOptions } from './system_status' ;
@@ -203,6 +204,10 @@ export class AutoscaledPool {
203204 private resolve : ( ( val ?: unknown ) => void ) | null = null ;
204205 private reject : ( ( reason ?: unknown ) => void ) | null = null ;
205206 private snapshotter : Snapshotter ;
207+
208+ /** Additional SystemStatus loadSignals - tracked here for initialization and cleanup */
209+ private loadSignals : LoadSignal [ ] ;
210+
206211 private systemStatus : SystemStatus ;
207212 private autoscaleInterval ! : BetterIntervalID ;
208213 private maybeRunInterval ! : BetterIntervalID ;
@@ -295,6 +300,7 @@ export class AutoscaledPool {
295300 } ) ;
296301 ssoCopy . config ??= this . config ;
297302 this . snapshotter = ssoCopy . snapshotter ;
303+ this . loadSignals = ssoCopy . loadSignals ?? [ ] ;
298304 this . systemStatus = new SystemStatus ( ssoCopy ) ;
299305 }
300306
@@ -366,6 +372,7 @@ export class AutoscaledPool {
366372 } ) ;
367373
368374 await this . snapshotter . start ( ) ;
375+ await Promise . all ( this . loadSignals . map ( ( s ) => s . start ( ) ) ) ;
369376
370377 // This interval checks the system status and updates the desired concurrency accordingly.
371378 this . autoscaleInterval = betterSetInterval ( this . _autoscale , this . autoscaleIntervalMillis ) ;
@@ -699,6 +706,7 @@ export class AutoscaledPool {
699706 betterClearInterval ( this . maybeRunInterval ) ;
700707 if ( this . tasksDonePerSecondInterval ) betterClearInterval ( this . tasksDonePerSecondInterval ) ;
701708 if ( this . snapshotter ) await this . snapshotter . stop ( ) ;
709+ await Promise . all ( this . loadSignals . map ( ( s ) => s . stop ( ) ) ) ;
702710 }
703711
704712 protected _incrementTasksDonePerSecond ( intervalCallback : ( ) => void ) {
0 commit comments