本文整理汇总了Golang中github.com/tedsuo/ifrit.Invoke函数的典型用法代码示例。如果您正苦于以下问题:Golang Invoke函数的具体用法?Golang Invoke怎么用?Golang Invoke使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Invoke函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
logger, reconfigurableSink := cf_lager.New("tps-listener")
initializeDropsonde(logger)
noaaClient := noaa.NewConsumer(*trafficControllerURL, &tls.Config{InsecureSkipVerify: *skipSSLVerification}, nil)
defer noaaClient.Close()
apiHandler := initializeHandler(logger, noaaClient, *maxInFlightRequests, initializeBBSClient(logger))
members := grouper.Members{
{"api", http_server.New(*listenAddr, apiHandler)},
}
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: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("file-server")
initializeDropsonde(logger)
members := grouper.Members{
{"file server", initializeServer(logger)},
}
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("ready")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例3: CellEvents
func (db *serviceClient) CellEvents(logger lager.Logger) <-chan models.CellEvent {
logger = logger.Session("cell-events")
disappearanceWatcher, disappeared := locket.NewDisappearanceWatcher(logger, db.consulClient, CellSchemaRoot(), db.clock)
process := ifrit.Invoke(disappearanceWatcher)
events := make(chan models.CellEvent)
go func() {
for {
select {
case keys, ok := <-disappeared:
if !ok {
process.Signal(os.Interrupt)
return
}
cellIDs := make([]string, len(keys))
for i, key := range keys {
cellIDs[i] = path.Base(key)
}
logger.Info("cell-disappeared", lager.Data{"cell_ids": cellIDs})
events <- models.NewCellDisappearedEvent(cellIDs)
}
}
}()
return events
}
示例4: main
func main() {
logger := configureLogger()
flag.Parse()
validateFlags(logger)
router := configureRouter(logger)
var server ifrit.Runner
server = http_server.New(*listenAddress, router)
members := grouper.Members{
{"server", server},
}
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")
}
示例5: 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("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
port, err := strconv.Atoi(strings.Split(*listenAddr, ":")[1])
if err != nil {
logger.Fatal("invalid-port", err)
}
clock := clock.NewClock()
auctioneerServiceClient := auctioneer.NewServiceClient(consulClient, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout,
initializeBBSClient(logger), *startingContainerWeight)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient, port)
registrationRunner := initializeRegistrationRunner(logger, consulClient, clock, port)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
{"registration-runner", registrationRunner},
}
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")
}
示例6: Run
func (ts *timeout) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
runProcess := ifrit.Invoke(ts.runStep)
timer := time.NewTimer(time.Duration(ts.duration))
var runErr error
var timeoutErr error
var sig os.Signal
dance:
for {
select {
case runErr = <-runProcess.Wait():
break dance
case <-timer.C:
ts.timedOut = true
timeoutErr = ErrStepTimedOut
runProcess.Signal(os.Kill)
case sig = <-signals:
runProcess.Signal(sig)
}
}
if timeoutErr != nil {
return timeoutErr
}
if runErr != nil {
return runErr
}
return nil
}
示例7: StartGarden
func StartGarden(gardenBin, containerizerBin string, argv ...string) (ifrit.Process, garden.Client) {
gardenPort, err := localip.LocalPort()
Expect(err).NotTo(HaveOccurred())
gardenAddr := fmt.Sprintf("127.0.0.1:%d", gardenPort)
tmpDir := os.TempDir()
// If below fails, try
// netsh advfirewall firewall add rule name="Open Port 48080" dir=in action=allow protocol=TCP localport=48080
containerizerPort, err := localip.LocalPort()
Expect(err).NotTo(HaveOccurred())
gardenRunner := garden_runner.New("tcp4", gardenAddr, tmpDir, gardenBin, fmt.Sprintf("http://127.0.0.1:%d", containerizerPort))
containerizerRunner := ginkgomon.New(ginkgomon.Config{
Name: "containerizer",
Command: exec.Command(containerizerBin, "127.0.0.1", strconv.Itoa(int(containerizerPort))),
AnsiColorCode: "",
StartCheck: "Control-C to quit.",
StartCheckTimeout: 10 * time.Second,
Cleanup: func() {},
})
group := grouper.NewOrdered(syscall.SIGTERM, []grouper.Member{
{Name: "containerizer", Runner: containerizerRunner},
{Name: "garden", Runner: gardenRunner},
})
gardenProcess := ifrit.Invoke(group)
return gardenProcess, gardenRunner.NewClient()
}
示例8: Execute
func (cmd *WebCommand) Execute(args []string) error {
tsa := &tsacmd.TSACommand{
BindIP: cmd.TSA.BindIP,
BindPort: cmd.TSA.BindPort,
HostKeyPath: cmd.TSA.HostKeyPath,
AuthorizedKeysPath: cmd.TSA.AuthorizedKeysPath,
HeartbeatInterval: cmd.TSA.HeartbeatInterval,
}
cmd.populateTSAFlagsFromATCFlags(tsa)
atcRunner, err := cmd.ATCCommand.Runner(args)
if err != nil {
return err
}
tsaRunner, err := tsa.Runner(args)
if err != nil {
return err
}
runner := sigmon.New(grouper.NewParallel(os.Interrupt, grouper.Members{
{"atc", atcRunner},
{"tsa", tsaRunner},
}))
return <-ifrit.Invoke(runner).Wait()
}
示例9: startGarden
func startGarden(argv ...string) garden.Client {
gardenAddr := fmt.Sprintf("/tmp/garden_%d.sock", GinkgoParallelNode())
gardenRunner = runner.New("unix", gardenAddr, gardenBin, argv...)
gardenProcess = ifrit.Invoke(gardenRunner)
return gardenRunner.NewClient()
}
示例10: SpinUp
func (f *FakeCell) SpinUp(serviceClient bbs.ServiceClient) {
//make a test-friendly AuctionRepDelegate using the auction package's SimulationRepDelegate
f.SimulationRep = simulationrep.New(f.stack, "Z0", rep.Resources{
DiskMB: 100,
MemoryMB: 100,
Containers: 100,
})
//spin up an http auction server
logger := lager.NewLogger(f.cellID)
logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))
fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
fakeExecutorClient := new(executorfakes.FakeClient)
fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)
handlers := rephandlers.New(f.SimulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger)
router, err := rata.NewRouter(rep.Routes, handlers)
Expect(err).NotTo(HaveOccurred())
f.server = httptest.NewServer(router)
presence := models.NewCellPresence(
f.cellID,
f.server.URL,
"az1",
models.NewCellCapacity(512, 1024, 124),
[]string{},
[]string{})
f.heartbeater = ifrit.Invoke(serviceClient.NewCellPresenceRunner(logger, &presence, time.Second))
}
示例11: MonitorJobFailures
func (w *windowsJobSupervisor) MonitorJobFailures(handler JobFailureHandler) error {
hl := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
if s.stateIs(stateDisabled) {
return
}
var event windowsServiceEvent
err := json.NewDecoder(r.Body).Decode(&event)
if err != nil {
s.logger.Error(s.logTag, "MonitorJobFailures received unknown request: %s", err)
return
}
handler(boshalert.MonitAlert{
Action: "Start",
Date: time.Now().Format(time.RFC1123Z),
Event: event.Event,
ID: event.ProcessName,
Service: event.ProcessName,
Description: fmt.Sprintf("exited with code %d", event.ExitCode),
})
})
server := http_server.New(fmt.Sprintf("localhost:%d", s.jobFailuresServerPort), hl)
process := ifrit.Invoke(server)
for {
select {
case <-s.cancelServer:
process.Signal(os.Kill)
case err := <-process.Wait():
if err != nil {
return bosherr.WrapError(err, "Listen for HTTP")
}
return nil
}
}
}
示例12: ServeAPI
func ServeAPI(l logger.Logger, conf *config.Config) {
store := connectToStore(l, conf)
apiHandler, err := handlers.New(l, store, buildTimeProvider(l))
if err != nil {
l.Error("initialize-handler.failed", err)
panic(err)
}
handler := handlers.BasicAuthWrap(apiHandler, conf.APIServerUsername, conf.APIServerPassword)
listenAddr := fmt.Sprintf("%s:%d", conf.APIServerAddress, conf.APIServerPort)
members := grouper.Members{
{"api", http_server.New(listenAddr, handler)},
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
l.Info("started")
l.Info(listenAddr)
err = <-monitor.Wait()
if err != nil {
l.Error("exited", err)
os.Exit(1)
}
l.Info("exited")
os.Exit(0)
}
示例13: StartDebugServer
func StartDebugServer(address string, sink *lager.ReconfigurableSink, metrics Metrics) (ifrit.Process, error) {
expvar.Publish("numCPUS", expvar.Func(func() interface{} {
return metrics.NumCPU()
}))
expvar.Publish("numGoRoutines", expvar.Func(func() interface{} {
return metrics.NumGoroutine()
}))
expvar.Publish("loopDevices", expvar.Func(func() interface{} {
return metrics.LoopDevices()
}))
expvar.Publish("backingStores", expvar.Func(func() interface{} {
return metrics.BackingStores()
}))
expvar.Publish("depotDirs", expvar.Func(func() interface{} {
return metrics.DepotDirs()
}))
server := http_server.New(address, handler(sink))
p := ifrit.Invoke(server)
select {
case <-p.Ready():
case err := <-p.Wait():
return nil, err
}
return p, nil
}
示例14: start
func start(creator RunnerCreator, network, addr string, argv ...string) *RunningGarden {
tmpDir := filepath.Join(
os.TempDir(),
fmt.Sprintf("test-garden-%d", ginkgo.GinkgoParallelNode()),
)
if GraphRoot == "" {
GraphRoot = filepath.Join(tmpDir, "graph")
}
graphPath := filepath.Join(GraphRoot, fmt.Sprintf("node-%d", ginkgo.GinkgoParallelNode()))
r := &RunningGarden{
GraphRoot: GraphRoot,
GraphPath: graphPath,
tmpdir: tmpDir,
logger: lagertest.NewTestLogger("garden-runner"),
Client: client.New(connection.New(network, addr)),
}
c := cmd(tmpDir, graphPath, network, addr, GardenBin, BinPath, RootFSPath, argv...)
r.process = ifrit.Invoke(creator.Create(c))
r.Pid = c.Process.Pid
return r
}
示例15: 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("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
client, err := consuladapter.NewClient(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
sessionMgr := consuladapter.NewSessionManager(client)
consulSession, err := consuladapter.NewSession("auctioneer", *lockTTL, client, sessionMgr)
if err != nil {
logger.Fatal("consul-session-failed", err)
}
clock := clock.NewClock()
bbsServiceClient := bbs.NewServiceClient(consulSession, clock)
auctioneerServiceClient := auctioneer.NewServiceClient(consulSession, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout, initializeBBSClient(logger), bbsServiceClient)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
}
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")
}