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


Golang Step.Cancel方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/executor/depot/steps.Step.Cancel方法的典型用法代码示例。如果您正苦于以下问题:Golang Step.Cancel方法的具体用法?Golang Step.Cancel怎么用?Golang Step.Cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/executor/depot/steps.Step的用法示例。


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

示例1:

			throttleChan = make(chan struct{}, numOfConcurrentMonitorSteps)
			doneChan = make(chan struct{}, 1)
			fakeStep = new(fakes.FakeStep)
			fakeStep.PerformStub = func() error {
				throttleChan <- struct{}{}
				<-doneChan
				return nil
			}
			checkFunc = func() steps.Step {
				return fakeStep
			}

		})

		AfterEach(func() {
			step.Cancel()
		})

		It("throttles concurrent health check", func() {
			for i := 0; i < 5; i++ {
				go step.Perform()
			}

			Consistently(fakeStep.PerformCallCount).Should(Equal(0))
			clock.Increment(501 * time.Millisecond)

			Eventually(func() int {
				return len(throttleChan)
			}).Should(Equal(numOfConcurrentMonitorSteps))
			Consistently(func() int {
				return len(throttleChan)
开发者ID:snowsnail,项目名称:executor,代码行数:31,代码来源:monitor_step_test.go

示例2: runStepProcess

func (store *GardenStore) runStepProcess(
	logger lager.Logger,
	step steps.Step,
	hasStartedRunning <-chan struct{},
	gardenContainer garden.Container,
	guid string,
) {
	process := ifrit.Invoke(ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
		logger := logger.Session("run-step-process")
		logger.Info("started")
		defer logger.Info("finished")
		seqComplete := make(chan error)

		close(ready)

		go func() {
			seqComplete <- step.Perform()
		}()

		result := executor.ContainerRunResult{}

		toldToStop := false

	OUTER_LOOP:
		for {
			select {
			case <-signals:
				signals = nil
				toldToStop = true

				logger.Info("signaled")
				step.Cancel()

			case <-hasStartedRunning:
				hasStartedRunning = nil
				logger.Info("transitioning-to-running")
				err := store.transitionToRunning(logger, gardenContainer)
				if err != nil {
					logger.Error("failed-transitioning-to-running", err)
					result.Failed = true
					result.FailureReason = err.Error()
					break OUTER_LOOP
				}
				logger.Info("succeeded-transitioning-to-running")

			case err := <-seqComplete:
				if err == nil {
					logger.Info("step-finished-normally")
				} else if toldToStop {
					logger.Info("step-cancelled")
					result.Stopped = true
				} else {
					logger.Info("step-finished-with-error", lager.Data{"error": err.Error()})
					result.Failed = true
					result.FailureReason = err.Error()
				}

				break OUTER_LOOP
			}
		}

		logger.Info("transitioning-to-complete")
		err := store.transitionToComplete(logger, gardenContainer, result)
		if err != nil {
			logger.Error("failed-transitioning-to-complete", err)
			return nil
		}
		logger.Info("succeeded-transitioning-to-complete")

		return nil
	}))

	store.processesL.Lock()
	store.runningProcesses[guid] = process
	numProcesses := len(store.runningProcesses)
	store.processesL.Unlock()

	logger.Info("stored-step-process", lager.Data{"num-step-processes": numProcesses})
}
开发者ID:snowsnail,项目名称:executor,代码行数:79,代码来源:garden_store.go


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