github.com/chenbh/concourse/v6@v6.4.2/atc/gc/build_collector.go (about)

     1  package gc
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"code.cloudfoundry.org/lager/lagerctx"
     8  	"github.com/chenbh/concourse/v6/atc/metric"
     9  )
    10  
    11  type buildCollector struct {
    12  	buildFactory buildFactory
    13  }
    14  
    15  type buildFactory interface {
    16  	MarkNonInterceptibleBuilds() error
    17  }
    18  
    19  func NewBuildCollector(buildFactory buildFactory) *buildCollector {
    20  	return &buildCollector{
    21  		buildFactory: buildFactory,
    22  	}
    23  }
    24  
    25  func (b *buildCollector) Run(ctx context.Context) error {
    26  	logger := lagerctx.FromContext(ctx).Session("build-collector")
    27  
    28  	start := time.Now()
    29  	defer func() {
    30  		metric.BuildCollectorDuration{
    31  			Duration: time.Since(start),
    32  		}.Emit(logger)
    33  	}()
    34  
    35  	logger.Debug("start")
    36  	defer logger.Debug("done")
    37  
    38  	return b.buildFactory.MarkNonInterceptibleBuilds()
    39  }