Example #1
0
File: volume.go Project: ACPK/atc
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
}