本文整理汇总了Golang中github.com/pivotal-golang/clock.Clock.NewTicker方法的典型用法代码示例。如果您正苦于以下问题:Golang Clock.NewTicker方法的具体用法?Golang Clock.NewTicker怎么用?Golang Clock.NewTicker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pivotal-golang/clock.Clock
的用法示例。
在下文中一共展示了Clock.NewTicker方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newVolume
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
}
示例2: newVolume
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
}
示例3: NewHardcoded
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
}
}
示例4: newGardenWorkerContainer
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 = "root"
}
return workerContainer, nil
}
示例5: NewRunner
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
}
}
})
}
示例6: newGardenWorkerContainer
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
}