@@ -33,7 +33,7 @@ class Logger {
3333 this . findExistingContainers = findExistingContainers === 'true' ;
3434 this . logSizeLimit = logSizeLimit ;
3535 this . containerLoggers = [ ] ;
36- this . logSize = 0 ;
36+ this . totalLogSize = 0 ;
3737 this . taskLogger = undefined ;
3838 this . buildFinishedPromise = buildFinishedPromise || Q . resolve ( ) ;
3939 this . finishedContainers = 0 ;
@@ -54,7 +54,7 @@ class Logger {
5454 } ) ;
5555 this . _readState ( ) ;
5656 this . _handleBuildFinished ( ) ;
57- this . _updateStateInterval = setInterval ( this . _updateStateFile . bind ( this ) , 1000 ) ;
57+ this . _updateStateInterval = setInterval ( this . _updateStateFile . bind ( this ) , 3000 ) ;
5858 }
5959
6060 /**
@@ -173,13 +173,7 @@ class Logger {
173173 logLimitExceeded ( ) {
174174 // TODO in the future when we allow a workflow to use multuple dinds, this will not be correct
175175 // we need to get the total size of logs from all dinds
176- return this . logSizeLimit && this . _getTotalLogSize ( ) > this . logSizeLimit ;
177- }
178-
179- _getTotalLogSize ( ) {
180- return _ . reduce ( this . containerLoggers , ( sum , containerLogger ) => {
181- return sum + containerLogger . logSize ;
182- } , 0 ) ;
176+ return this . logSizeLimit && this . totalLogSize > this . logSizeLimit ;
183177 }
184178
185179 /**
@@ -263,7 +257,7 @@ class Logger {
263257 } ) ;
264258 this . containerLoggers . push ( containerLogger ) ;
265259 containerLogger . on ( 'message.logged' , this . _updateTotalLogSize . bind ( this ) ) ;
266- containerLogger . once ( 'end' , this . _handleContainerStreamEnd . bind ( this ) ) ;
260+ containerLogger . once ( 'end' , this . _handleContainerStreamEnd . bind ( this , containerId ) ) ;
267261
268262 containerLogger . start ( )
269263 . done ( ( ) => {
@@ -287,9 +281,9 @@ class Logger {
287281 _ . set ( this , 'state.logsStatus.missingLogs' , writeCalls - resolvedCalls - rejectedCalls ) ;
288282 }
289283
290- _updateTotalLogSize ( ) {
291- this . logSize = this . _getTotalLogSize ( ) ;
292- this . taskLogger . setLogSize ( this . logSize ) ;
284+ _updateTotalLogSize ( size ) {
285+ this . totalLogSize += size ;
286+ this . taskLogger . setLogSize ( this . totalLogSize ) ;
293287 }
294288
295289 _updateLastLoggingDate ( ) {
@@ -301,9 +295,16 @@ class Logger {
301295 clearInterval ( this . _updateStateInterval ) ;
302296 } else {
303297 this . _writeNewState ( true ) ;
304-
305298 if ( this . showProgress ) {
299+ const activeContainerLoggers = this . containerLoggers . filter (
300+ ( containerLogger ) => this . state . containers [ containerLogger . containerId ] . status === ContainerHandlingStatus . LISTENING
301+ ) ;
302+ const buffers = activeContainerLoggers . reduce ( ( acc , cur ) => {
303+ acc [ cur . containerId ] = cur . bufferUsed ;
304+ return acc ;
305+ } , { } ) ;
306306 logger . debug ( `logger progress update: ${ JSON . stringify ( this . state . logsStatus ) } ` ) ;
307+ logger . debug ( `buffers: ${ JSON . stringify ( buffers ) } ` ) ;
307308 }
308309 }
309310 }
@@ -376,9 +377,10 @@ class Logger {
376377 } ) ;
377378 }
378379
379- _handleContainerStreamEnd ( ) {
380+ _handleContainerStreamEnd ( containerId ) {
380381 this . finishedContainers ++ ;
381382 this . finishedContainersEmitter . emit ( 'end' ) ;
383+ this . state . containers [ containerId ] = { status : ContainerHandlingStatus . FINISHED } ;
382384 }
383385
384386 // do not call before build is finished
0 commit comments