github.com/chenbh/concourse/v6@v6.4.2/atc/gc/resource_config_check_session_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 multierror "github.com/hashicorp/go-multierror" 11 ) 12 13 type resourceConfigCheckSessionCollector struct { 14 configCheckSessionLifecycle db.ResourceConfigCheckSessionLifecycle 15 } 16 17 func NewResourceConfigCheckSessionCollector( 18 configCheckSessionLifecycle db.ResourceConfigCheckSessionLifecycle, 19 ) *resourceConfigCheckSessionCollector { 20 return &resourceConfigCheckSessionCollector{ 21 configCheckSessionLifecycle: configCheckSessionLifecycle, 22 } 23 } 24 25 func (rccsc *resourceConfigCheckSessionCollector) Run(ctx context.Context) error { 26 logger := lagerctx.FromContext(ctx).Session("resource-config-check-session-collector") 27 28 logger.Debug("start") 29 defer logger.Debug("done") 30 31 start := time.Now() 32 defer func() { 33 metric.ResourceConfigCheckSessionCollectorDuration{ 34 Duration: time.Since(start), 35 }.Emit(logger) 36 }() 37 38 var errs error 39 40 err := rccsc.configCheckSessionLifecycle.CleanExpiredResourceConfigCheckSessions() 41 if err != nil { 42 errs = multierror.Append(errs, err) 43 logger.Error("failed-to-clean-up-expired-resource-config-check-sessions", err) 44 } 45 46 err = rccsc.configCheckSessionLifecycle.CleanInactiveResourceConfigCheckSessions() 47 if err != nil { 48 errs = multierror.Append(errs, err) 49 logger.Error("failed-to-clean-up-inactive-resource-config-check-sessions", err) 50 } 51 52 return errs 53 }