github.com/chenbh/concourse/v6@v6.4.2/atc/gc/resource_cache_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/db"
     9  	"github.com/chenbh/concourse/v6/atc/metric"
    10  )
    11  
    12  type resourceCacheCollector struct {
    13  	cacheLifecycle db.ResourceCacheLifecycle
    14  }
    15  
    16  func NewResourceCacheCollector(cacheLifecycle db.ResourceCacheLifecycle) *resourceCacheCollector {
    17  	return &resourceCacheCollector{
    18  		cacheLifecycle: cacheLifecycle,
    19  	}
    20  }
    21  
    22  func (rcc *resourceCacheCollector) Run(ctx context.Context) error {
    23  	logger := lagerctx.FromContext(ctx).Session("resource-cache-collector")
    24  
    25  	logger.Debug("start")
    26  	defer logger.Debug("done")
    27  
    28  	start := time.Now()
    29  	defer func() {
    30  		metric.ResourceCacheCollectorDuration{
    31  			Duration: time.Since(start),
    32  		}.Emit(logger)
    33  	}()
    34  
    35  	return rcc.cacheLifecycle.CleanUpInvalidCaches(logger)
    36  }