func newVolume(logger lager.Logger, bcVol baggageclaim.Volume, clock clock.Clock, db VolumeFactoryDB) (Volume, bool, error) { vol := &volume{ Volume: bcVol, db: db, heartbeating: new(sync.WaitGroup), release: make(chan *time.Duration, 1), } ttl, found, err := vol.db.GetVolumeTTL(vol.Handle()) if err != nil { logger.Error("failed-to-lookup-expiration-of-volume", err) return nil, false, err } if !found { return nil, false, nil } vol.heartbeat(logger.Session("initial-heartbeat"), ttl) vol.heartbeating.Add(1) go vol.heartbeatContinuously( logger.Session("continuous-heartbeat"), clock.NewTicker(volumeKeepalive), ttl, ) return vol, true, nil }
func newVolume(logger lager.Logger, bcVol baggageclaim.Volume, clock clock.Clock, db VolumeFactoryDB) Volume { vol := &volume{ Volume: bcVol, db: db, heartbeating: new(sync.WaitGroup), release: make(chan time.Duration, 1), } ttl, err := vol.db.GetVolumeTTL(vol.Handle()) if err != nil { logger.Info("failed-to-lookup-ttl", lager.Data{"error": err.Error()}) ttl, _, err = bcVol.Expiration() if err != nil { logger.Error("failed-to-lookup-expiration-of-volume", err) return nil } } vol.heartbeat(logger.Session("initial-heartbeat"), ttl) vol.heartbeating.Add(1) go vol.heartbeatContinuously( logger.Session("continuos-heartbeat"), clock.NewTicker(volumeKeepalive), ttl, ) return vol }
func NewHardcoded( logger lager.Logger, workerDB SaveWorkerDB, clock c.Clock, gardenAddr string, baggageclaimURL string, resourceTypesNG []atc.WorkerResourceType, ) ifrit.RunFunc { return func(signals <-chan os.Signal, ready chan<- struct{}) error { workerInfo := db.WorkerInfo{ GardenAddr: gardenAddr, BaggageclaimURL: baggageclaimURL, ActiveContainers: 0, ResourceTypes: resourceTypesNG, Platform: "linux", Tags: []string{}, Name: gardenAddr, } err := workerDB.SaveWorker(workerInfo, 30*time.Second) if err != nil { logger.Error("could-not-save-garden-worker-provided", err) return err } ticker := clock.NewTicker(10 * time.Second) close(ready) dance: for { select { case <-ticker.C(): err = workerDB.SaveWorker(workerInfo, 30*time.Second) if err != nil { logger.Error("could-not-save-garden-worker-provided", err) } case <-signals: ticker.Stop() break dance } } return nil } }
func newGardenWorkerContainer( logger lager.Logger, container garden.Container, gardenClient garden.Client, baggageclaimClient baggageclaim.Client, db GardenWorkerDB, clock clock.Clock, volumeFactory VolumeFactory, ) (Container, error) { workerContainer := &gardenWorkerContainer{ Container: container, gardenClient: gardenClient, db: db, clock: clock, heartbeating: new(sync.WaitGroup), release: make(chan *time.Duration, 1), } workerContainer.heartbeat(logger.Session("initial-heartbeat"), ContainerTTL) workerContainer.heartbeating.Add(1) go workerContainer.heartbeatContinuously( logger.Session("continuous-heartbeat"), clock.NewTicker(containerKeepalive), ) metric.TrackedContainers.Inc() properties, err := workerContainer.Properties() if err != nil { workerContainer.Release(nil) return nil, err } err = workerContainer.initializeVolumes(logger, properties, baggageclaimClient, volumeFactory) if err != nil { workerContainer.Release(nil) return nil, err } if properties["user"] != "" { workerContainer.user = properties["user"] } else { workerContainer.user = "******" } return workerContainer, nil }
func NewRunner( logger lager.Logger, baggageCollector BaggageCollector, db RunnerDB, clock clock.Clock, interval time.Duration, ) ifrit.Runner { return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error { close(ready) ticker := clock.NewTicker(interval) defer ticker.Stop() for { select { case <-ticker.C(): leaseLogger := logger.Session("lease-invalidate-cache") leaseLogger.Info("tick") lease, leased, err := db.LeaseCacheInvalidation(leaseLogger, interval) if err != nil { leaseLogger.Error("failed-to-get-lease", err) break } if !leased { leaseLogger.Debug("did-not-get-lease") break } leaseLogger.Info("collecting-baggage") err = baggageCollector.Collect() if err != nil { leaseLogger.Error("failed-to-collect-baggage", err) } lease.Break() case <-signals: return nil } } }) }
func newGardenWorkerContainer(container garden.Container, gardenClient garden.Client, clock clock.Clock) Container { workerContainer := &gardenWorkerContainer{ Container: container, gardenClient: gardenClient, clock: clock, heartbeating: new(sync.WaitGroup), stopHeartbeating: make(chan struct{}), } workerContainer.heartbeating.Add(1) go workerContainer.heartbeat(clock.NewTicker(containerKeepalive)) trackedContainers.Add(1) return workerContainer }