当前位置: 首页>>代码示例>>Golang>>正文


Golang ifrit.Background函数代码示例

本文整理汇总了Golang中github.com/tedsuo/ifrit.Background函数的典型用法代码示例。如果您正苦于以下问题:Golang Background函数的具体用法?Golang Background怎么用?Golang Background使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Background函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (r Restarter) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	if r.Load == nil {
		return ErrNoLoadCallback
	}

	process := ifrit.Background(r.Runner)
	processReady := process.Ready()
	exit := process.Wait()
	signaled := false

	for {
		select {
		case signal := <-signals:
			process.Signal(signal)
			signaled = true

		case <-processReady:
			close(ready)
			processReady = nil

		case err := <-exit:
			if signaled {
				return err
			}

			r.Runner = r.Load(r.Runner, err)
			if r.Runner == nil {
				return err
			}
			process = ifrit.Background(r.Runner)
			exit = process.Wait()
		}
	}
}
开发者ID:cwlbraa,项目名称:ifrit,代码行数:34,代码来源:restart.go

示例2: Run

func (step *composed) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	step.firstStep = step.a.Using(step.prev, step.repo)

	firstProcess := ifrit.Background(step.firstStep)

	var signalled bool
	var waitErr error

dance:
	for {
		select {
		case waitErr = <-firstProcess.Wait():
			break dance

		case sig := <-signals:
			firstProcess.Signal(sig)
			signalled = true
		}
	}

	if signalled || waitErr != nil {
		return waitErr
	}

	step.secondStep = step.b.Using(step.firstStep, step.repo)

	return step.secondStep.Run(signals, ready)
}
开发者ID:savaki,项目名称:atc,代码行数:28,代码来源:compose.go

示例3: 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
	}))
}
开发者ID:savaki,项目名称:tsa,代码行数:29,代码来源:server.go

示例4: Resume

func (build *execBuild) Resume(logger lager.Logger) {
	stepFactory := build.buildStepFactory(logger, build.metadata.Plan)
	source := stepFactory.Using(&exec.NoopStep{}, exec.NewSourceRepository())

	defer source.Release()

	process := ifrit.Background(source)

	exited := process.Wait()

	aborted := false
	var succeeded exec.Success

	for {
		select {
		case err := <-exited:
			if aborted {
				succeeded = false
			} else if !source.Result(&succeeded) {
				logger.Error("step-had-no-result", errors.New("step failed to provide us with a result"))
				succeeded = false
			}

			build.delegate.Finish(logger.Session("finish"), err, succeeded, aborted)
			return

		case sig := <-build.signals:
			process.Signal(sig)

			if sig == os.Kill {
				aborted = true
			}
		}
	}
}
开发者ID:xoebus,项目名称:checkin,代码行数:35,代码来源:exec_engine.go

示例5: heartbeat

func (m *Maintainer) heartbeat(sigChan <-chan os.Signal, ready chan<- struct{}, heartbeater ifrit.Runner) error {
	m.logger.Info("start-heartbeating")
	defer m.logger.Info("complete-heartbeating")
	ticker := m.clock.NewTicker(m.RetryInterval)
	defer ticker.Stop()

	heartbeatProcess := ifrit.Background(heartbeater)
	heartbeatExitChan := heartbeatProcess.Wait()
	select {
	case <-heartbeatProcess.Ready():
		m.logger.Info("ready")
	case err := <-heartbeatExitChan:
		if err != nil {
			m.logger.Error("heartbeat-exited", err)
		}
		return err
	case <-sigChan:
		m.logger.Info("signaled-while-starting-heatbeater")
		heartbeatProcess.Signal(os.Kill)
		<-heartbeatExitChan
		return nil
	}

	if ready != nil {
		close(ready)
	}

	for {
		select {
		case err := <-heartbeatExitChan:
			m.logger.Error("heartbeat-lost-lock", err)
			return err

		case <-sigChan:
			m.logger.Info("signaled-while-heartbeating")
			heartbeatProcess.Signal(os.Kill)
			<-heartbeatExitChan
			return nil

		case <-ticker.C():
			m.logger.Debug("heartbeat-pinging-executor")
			err := m.executorClient.Ping()
			if err == nil {
				continue
			}

			m.logger.Info("start-signaling-heartbeat-to-stop")
			heartbeatProcess.Signal(os.Kill)
			select {
			case <-heartbeatExitChan:
				m.logger.Info("heartbeat-stopped")
				return err
			case <-sigChan:
				m.logger.Info("signaled-while-waiting-for-heartbeat-to-stop")
				return nil
			}
		}
	}
}
开发者ID:jianhuiz,项目名称:rep,代码行数:59,代码来源:maintain.go

示例6: heartbeatWorker

func (server *registrarSSHServer) heartbeatWorker(logger lager.Logger, worker atc.Worker, channel ssh.Channel) ifrit.Process {
	return ifrit.Background(tsa.NewHeartbeater(
		logger,
		server.heartbeatInterval,
		gclient.New(gconn.New("tcp", worker.Addr)),
		server.atcEndpoint,
		worker,
		channel,
	))
}
开发者ID:savaki,项目名称:tsa,代码行数:10,代码来源:server.go

示例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()
	})
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:10,代码来源:proxy.go

示例8: Invoke

func Invoke(runner ifrit.Runner) ifrit.Process {
	process := ifrit.Background(runner)

	select {
	case <-process.Ready():
	case err := <-process.Wait():
		ginkgo.Fail(fmt.Sprintf("process failed to start: %s", err))
	}

	return process
}
开发者ID:trainchou,项目名称:gorouter,代码行数:11,代码来源:helpers.go

示例9: orderedStart

func (g *orderedGroup) orderedStart(signals <-chan os.Signal) (os.Signal, ErrorTrace) {
	for _, member := range g.members {
		p := ifrit.Background(member)
		cases := make([]reflect.SelectCase, 0, len(g.pool)+3)
		for i := 0; i < len(g.pool); i++ {
			cases = append(cases, reflect.SelectCase{
				Dir:  reflect.SelectRecv,
				Chan: reflect.ValueOf(g.pool[g.members[i].Name].Wait()),
			})
		}
		cases = append(cases, reflect.SelectCase{
			Dir:  reflect.SelectRecv,
			Chan: reflect.ValueOf(p.Ready()),
		})

		cases = append(cases, reflect.SelectCase{
			Dir:  reflect.SelectRecv,
			Chan: reflect.ValueOf(p.Wait()),
		})

		cases = append(cases, reflect.SelectCase{
			Dir:  reflect.SelectRecv,
			Chan: reflect.ValueOf(signals),
		})

		chosen, recv, _ := reflect.Select(cases)
		g.pool[member.Name] = p
		switch chosen {
		case len(cases) - 1:
			// signals
			return recv.Interface().(os.Signal), nil
		case len(cases) - 2:
			// p.Wait
			return nil, ErrorTrace{
				ExitEvent{Member: member, Err: recv.Interface().(error)},
			}
		case len(cases) - 3:
			// p.Ready
		default:
			// other member has exited
			var err error = nil
			if e := recv.Interface(); e != nil {
				err = e.(error)
			}
			return nil, ErrorTrace{
				ExitEvent{Member: g.members[chosen], Err: err},
			}
		}
	}

	return nil, nil
}
开发者ID:cwlbraa,项目名称:ifrit,代码行数:52,代码来源:ordered.go

示例10: Run

func (r *groupRunner) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	processes := []ifrit.Process{}
	processChan := make(chan ifrit.Process)
	exitTrace := make(ExitTrace, 0, len(r.members))
	exitEvents := make(chan ExitEvent)
	shutdown := false

	go func() {
		for _, member := range r.members {
			process := ifrit.Background(member)
			go func(member Member) {
				err := <-process.Wait()
				exitEvents <- ExitEvent{
					Err:    err,
					Member: member,
				}
			}(member)
			processChan <- process
			<-process.Ready()
		}
		close(ready)
	}()

	for {
		select {
		case sig := <-signals:
			shutdown = true
			for _, process := range processes {
				process.Signal(sig)
			}

		case process := <-processChan:
			processes = append(processes, process)

		case exit := <-exitEvents:
			exitTrace = append(exitTrace, exit)

			if len(exitTrace) == len(processes) {
				return exitTrace.ToError()
			}

			if shutdown {
				break
			}

			shutdown = true
			for _, process := range processes {
				process.Signal(os.Interrupt)
			}
		}
	}
}
开发者ID:glyn,项目名称:gunk,代码行数:52,代码来源:group_runner.go

示例11: Run

func (step aggregateStep) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	members := []ifrit.Process{}

	for _, ms := range step {
		process := ifrit.Background(ms)
		members = append(members, process)
	}

	for _, mp := range members {
		select {
		case <-mp.Ready():
		case <-mp.Wait():
		}
	}

	close(ready)

	var errorMessages []string

dance:
	for _, mp := range members {
		select {
		case sig := <-signals:
			for _, mp := range members {
				mp.Signal(sig)
			}

			for _, mp := range members {
				err := <-mp.Wait()
				if err != nil {
					errorMessages = append(errorMessages, err.Error())
				}
			}

			break dance
		case err := <-mp.Wait():
			if err != nil {
				errorMessages = append(errorMessages, err.Error())
			}
		}
	}

	if len(errorMessages) > 0 {
		return fmt.Errorf("sources failed:\n%s", strings.Join(errorMessages, "\n"))
	}

	return nil
}
开发者ID:utako,项目名称:atc,代码行数:48,代码来源:aggregate.go

示例12: parallelStart

func (g *parallelGroup) parallelStart(signals <-chan os.Signal) (os.Signal, ErrorTrace) {
	numMembers := len(g.members)

	processes := make([]ifrit.Process, numMembers)
	cases := make([]reflect.SelectCase, 2*numMembers+1)

	for i, member := range g.members {
		process := ifrit.Background(member)

		processes[i] = process

		cases[2*i] = reflect.SelectCase{
			Dir:  reflect.SelectRecv,
			Chan: reflect.ValueOf(process.Wait()),
		}

		cases[2*i+1] = reflect.SelectCase{
			Dir:  reflect.SelectRecv,
			Chan: reflect.ValueOf(process.Ready()),
		}
	}

	cases[2*numMembers] = reflect.SelectCase{
		Dir:  reflect.SelectRecv,
		Chan: reflect.ValueOf(signals),
	}

	numReady := 0
	for {
		chosen, recv, _ := reflect.Select(cases)

		switch {
		case chosen == 2*numMembers:
			return recv.Interface().(os.Signal), nil
		case chosen%2 == 0:
			recvError, _ := recv.Interface().(error)
			return nil, ErrorTrace{ExitEvent{Member: g.members[chosen/2], Err: recvError}}
		default:
			cases[chosen].Chan = reflect.Zero(cases[chosen].Chan.Type())
			g.pool[g.members[chosen/2].Name] = processes[chosen/2]
			numReady++
			if numReady == numMembers {
				return nil, nil
			}
		}
	}
}
开发者ID:julz,项目名称:garden-runc,代码行数:47,代码来源:parallel.go

示例13: orderedStart

func (g *orderedGroup) orderedStart(signals <-chan os.Signal) (os.Signal, ErrorTrace) {
	for _, member := range g.members {
		p := ifrit.Background(member)
		select {
		case <-p.Ready():
			g.pool[member.Name] = p
		case err := <-p.Wait():
			return nil, ErrorTrace{
				ExitEvent{Member: member, Err: err},
			}
		case signal := <-signals:
			return signal, nil
		}
	}

	return nil, nil
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:17,代码来源:ordered.go

示例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)
			}
		}
	})
}
开发者ID:xoebus,项目名称:checkin,代码行数:20,代码来源:command.go

示例15: Run

func (s sigmon) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	osSignals := make(chan os.Signal, SIGNAL_BUFFER_SIZE)
	signal.Notify(osSignals, s.Signals...)

	process := ifrit.Background(s.Runner)
	pReady := process.Ready()
	pWait := process.Wait()

	for {
		select {
		case sig := <-signals:
			process.Signal(sig)
		case sig := <-osSignals:
			process.Signal(sig)
		case <-pReady:
			close(ready)
			pReady = nil
		case err := <-pWait:
			signal.Stop(osSignals)
			return err
		}
	}
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:23,代码来源:sigmon.go


注:本文中的github.com/tedsuo/ifrit.Background函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。