本文整理汇总了Golang中github.com/tedsuo/ifrit.RunFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang RunFunc函数的具体用法?Golang RunFunc怎么用?Golang RunFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New(*sessionName)
natsClient := diegonats.NewClient()
clock := clock.NewClock()
syncer := syncer.NewSyncer(clock, *syncInterval, natsClient, logger)
initializeDropsonde(logger)
natsClientRunner := diegonats.NewClientRunner(*natsAddresses, *natsUsername, *natsPassword, logger, natsClient)
table := initializeRoutingTable()
emitter := initializeNatsEmitter(natsClient, logger)
watcher := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return watcher.NewWatcher(initializeBBSClient(logger), clock, table, emitter, syncer.Events(), logger).Run(signals, ready)
})
syncRunner := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return syncer.Run(signals, ready)
})
lockMaintainer := initializeLockMaintainer(logger, *consulCluster, *sessionName, *lockTTL, *lockRetryInterval, clock)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"nats-client", natsClientRunner},
{"watcher", watcher},
{"syncer", syncRunner},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例2: Consul
func (maker ComponentMaker) Consul(argv ...string) ifrit.Runner {
_, port, err := net.SplitHostPort(maker.Addresses.Consul)
Expect(err).NotTo(HaveOccurred())
httpPort, err := strconv.Atoi(port)
Expect(err).NotTo(HaveOccurred())
startingPort := httpPort - consulrunner.PortOffsetHTTP
clusterRunner := consulrunner.NewClusterRunner(startingPort, 1, "http")
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
done := make(chan struct{})
go func() {
clusterRunner.Start()
close(done)
}()
Eventually(done, 10).Should(BeClosed())
close(ready)
select {
case <-signals:
clusterRunner.Stop()
}
return nil
})
}
示例3: Put
func (resource *resource) Put(ioConfig IOConfig, source atc.Source, params atc.Params, artifactSource ArtifactSource) VersionedSource {
resourceDir := ResourcesDir("put")
vs := &versionedSource{
container: resource.container,
resourceDir: resourceDir,
}
vs.Runner = ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return resource.runScript(
"/opt/resource/out",
[]string{resourceDir},
outRequest{
Params: params,
Source: source,
},
&vs.versionResult,
ioConfig.Stderr,
artifactSource,
vs,
true,
).Run(signals, ready)
})
return vs
}
示例4: forwardTCPIP
func (server *registrarSSHServer) forwardTCPIP(
logger lager.Logger,
conn *ssh.ServerConn,
listener net.Listener,
forwardIP string,
forwardPort uint32,
) ifrit.Process {
return ifrit.Background(ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
go func() {
<-signals
listener.Close()
}()
close(ready)
for {
localConn, err := listener.Accept()
if err != nil {
logger.Error("failed-to-accept", err)
break
}
go forwardLocalConn(logger, localConn, conn, forwardIP, forwardPort)
}
return nil
}))
}
示例5: Scanner
func (radar *Radar) Scanner(logger lager.Logger, resourceName string) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
ticker := time.NewTicker(radar.interval)
close(ready)
for {
select {
case <-signals:
return nil
case <-ticker.C:
lock := radar.checkLock(radar.db.ScopedName(resourceName))
resourceCheckingLock, err := radar.locker.AcquireWriteLockImmediately(lock)
if err != nil {
continue
}
err = radar.scan(logger.Session("tick"), resourceName)
resourceCheckingLock.Release()
if err != nil {
return err
}
}
}
})
}
示例6: closeHub
func closeHub(hub event.Hub) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
<-signals
hub.Close()
return nil
})
}
示例7: New
func New(proxySignals <-chan os.Signal, runner ifrit.Runner) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
process := ifrit.Background(runner)
<-process.Ready()
close(ready)
go forwardSignals(proxySignals, process)
go forwardSignals(signals, process)
return <-process.Wait()
})
}
示例8: constructStopper
func constructStopper(database db.DB) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
select {
case <-signals:
database.CancelWatches()
}
return nil
})
}
示例9: constructStopper
func constructStopper(stopChan chan struct{}) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
select {
case <-signals:
close(stopChan)
}
return nil
})
}
示例10: RegistryPruner
func (a *AllocationStore) RegistryPruner(logger lager.Logger, expirationTime time.Duration) ifrit.Runner {
logger = logger.Session("allocation-store-pruner")
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
ticker := a.clock.NewTicker(expirationTime / 2)
defer ticker.Stop()
close(ready)
for {
select {
case <-signals:
logger.Info("exiting-pruning-loop")
return nil
case <-ticker.C():
logger.Debug("checking-for-expired-containers")
expiredAllocations := []string{}
a.lock.Lock()
for guid, container := range a.allocated {
if container.State != executor.StateReserved {
// only prune reserved containers
continue
}
lifespan := a.clock.Now().Sub(time.Unix(0, container.AllocatedAt))
if lifespan >= expirationTime {
logger.Info("reserved-container-expired", lager.Data{"guid": guid, "lifespan": lifespan})
expiredAllocations = append(expiredAllocations, guid)
}
}
if len(expiredAllocations) > 0 {
logger.Info("reaping-expired-allocations", lager.Data{"num-reaped": len(expiredAllocations)})
} else {
logger.Info("no-expired-allocations-found")
}
for _, guid := range expiredAllocations {
logger.Info("deleting-expired-container", lager.Data{"guid": guid})
delete(a.allocated, guid)
}
a.lock.Unlock()
}
}
return nil
})
}
示例11: closeHub
func closeHub(logger lager.Logger, hub event.Hub) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
logger.Info("starting")
defer logger.Info("finished")
close(ready)
logger.Info("started")
<-signals
logger.Info("shutting-down")
hub.Close()
return nil
})
}
示例12: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
logger, reconfigurableSink := cf_lager.New("tps-watcher")
initializeDropsonde(logger)
lockMaintainer := initializeLockMaintainer(logger)
ccClient := cc_client.NewCcClient(*ccBaseURL, *ccUsername, *ccPassword, *skipCertVerify)
watcher := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
w, err := watcher.NewWatcher(logger, *eventHandlingWorkers, initializeBBSClient(logger), ccClient)
if err != nil {
return err
}
return w.Run(signals, ready)
})
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"watcher", watcher},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例13: 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
}
}
})
}
示例14: onReady
func onReady(runner ifrit.Runner, cb func()) ifrit.Runner {
return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
process := ifrit.Background(runner)
subExited := process.Wait()
subReady := process.Ready()
for {
select {
case <-subReady:
cb()
subReady = nil
case err := <-subExited:
return err
case sig := <-signals:
process.Signal(sig)
}
}
})
}
示例15:
taskDB = new(dbfakes.FakeTaskDB)
taskDB.ResolvingTaskReturns(nil)
taskDB.DeleteTaskReturns(nil)
})
simulateTaskCompleting := func(signals <-chan os.Signal, ready chan<- struct{}) error {
close(ready)
task = model_helpers.NewValidTask("the-task-guid")
task.CompletionCallbackUrl = callbackURL
taskworkpool.HandleCompletedTask(logger, httpClient, taskDB, task)
return nil
}
var process ifrit.Process
JustBeforeEach(func() {
process = ifrit.Invoke(ifrit.RunFunc(simulateTaskCompleting))
})
AfterEach(func() {
ginkgomon.Kill(process)
})
Context("when the task has a completion callback URL", func() {
BeforeEach(func() {
Expect(taskDB.ResolvingTaskCallCount()).To(Equal(0))
})
It("marks the task as resolving", func() {
statusCodes <- 200
Eventually(taskDB.ResolvingTaskCallCount).Should(Equal(1))