本文整理汇总了Golang中github.com/wercker/wercker/util.NewTimer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTimer函数的具体用法?Golang NewTimer怎么用?Golang NewTimer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTimer函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CopySource
// CopySource copies the source into the HostPath
func (p *Runner) CopySource() error {
timer := util.NewTimer()
f := p.formatter
err := os.MkdirAll(p.options.HostPath(), 0755)
if err != nil {
return err
}
// Link the path to BuildPath("latest") for easy access
err = os.RemoveAll(p.options.BuildPath("latest"))
if err != nil {
return err
}
err = os.Symlink(p.options.HostPath(), p.options.BuildPath("latest"))
if err != nil {
return err
}
err = os.Symlink(p.ProjectDir(), p.options.HostPath("source"))
if err != nil {
return err
}
if p.options.Verbose {
p.logger.Printf(f.Success("Source -> Staging Area", timer.String()))
}
return nil
}
示例2: SetupGuest
// SetupGuest ensures that the guest is prepared to run the pipeline.
func (p *BasePipeline) SetupGuest(sessionCtx context.Context, sess *Session) error {
sess.HideLogs()
defer sess.ShowLogs()
timer := util.NewTimer()
f := &util.Formatter{p.options.GlobalOptions.ShowColors}
cmds := []string{}
if !p.options.DirectMount {
cmds = append(cmds,
// Make sure our guest path exists
fmt.Sprintf(`mkdir -p "%s"`, p.options.GuestPath()),
// Make sure our base path exists
fmt.Sprintf(`rm -rf "%s"`, filepath.Dir(p.options.BasePath())),
fmt.Sprintf(`mkdir -p "%s"`, filepath.Dir(p.options.BasePath())),
// Copy the source from the mounted directory to the base path
fmt.Sprintf(`cp -r "%s" "%s"`, p.options.MntPath("source"), p.options.BasePath()),
// Copy the cache from the mounted directory to the pipeline dir
fmt.Sprintf(`cp -r "%s" "%s"`, p.options.MntPath("cache"), p.options.GuestPath("cache")),
)
}
// Make sure the output path exists
cmds = append(cmds, fmt.Sprintf(`mkdir -p "%s"`, p.options.GuestPath("output")))
cmds = append(cmds, fmt.Sprintf(`chmod a+rx "%s"`, p.options.BasePath()))
p.logger.Printf(f.Info("Copying source to container"))
for _, cmd := range cmds {
exit, _, err := sess.SendChecked(sessionCtx, cmd)
if exit != 0 {
return fmt.Errorf("Guest command failed with exit code %d: %s", exit, cmd)
}
if err != nil {
return err
}
}
if p.options.Verbose {
p.logger.Printf(f.Success("Source+Cache -> Guest", timer.String()))
}
return nil
}
示例3: AddServices
// AddServices fetches and links the services to the base box.
func (p *Runner) AddServices(ctx context.Context, pipeline core.Pipeline, box core.Box) error {
f := p.formatter
timer := util.NewTimer()
for _, service := range pipeline.Services() {
timer.Reset()
if _, err := service.Fetch(ctx, pipeline.Env()); err != nil {
return err
}
box.AddService(service)
if p.options.Verbose {
p.logger.Printf(f.Success(fmt.Sprintf("Fetched %s", service.GetName()), timer.String()))
}
// TODO(mh): We want to make sure container is running fully before
// allowing build steps to run. We may need custom steps which block
// until service services are running.
}
return nil
}
示例4: CopyCache
// CopyCache copies the source into the HostPath
func (p *Runner) CopyCache() error {
timer := util.NewTimer()
f := p.formatter
err := os.MkdirAll(p.options.CachePath(), 0755)
if err != nil {
return err
}
err = os.Symlink(p.options.CachePath(), p.options.HostPath("cache"))
if err != nil {
return err
}
if p.options.Verbose {
p.logger.Printf(f.Success("Cache -> Staging Area", timer.String()))
}
if p.options.Verbose {
p.logger.Printf(f.Success("Cache -> Staging Area", timer.String()))
}
return nil
}
示例5: executePipeline
func executePipeline(cmdCtx context.Context, options *core.PipelineOptions, dockerOptions *dockerlocal.DockerOptions, getter pipelineGetter) (*RunnerShared, error) {
// Boilerplate
soft := NewSoftExit(options.GlobalOptions)
logger := util.RootLogger().WithField("Logger", "Main")
e, err := core.EmitterFromContext(cmdCtx)
if err != nil {
return nil, err
}
f := &util.Formatter{options.GlobalOptions.ShowColors}
// Set up the runner
r, err := NewRunner(cmdCtx, options, dockerOptions, getter)
if err != nil {
return nil, err
}
// Main timer
mainTimer := util.NewTimer()
timer := util.NewTimer()
// These will be emitted at the end of the execution, we're going to be
// pessimistic and report that we failed, unless overridden at the end of the
// execution.
fullPipelineFinisher := r.StartFullPipeline(options)
pipelineArgs := &core.FullPipelineFinishedArgs{}
defer fullPipelineFinisher.Finish(pipelineArgs)
buildFinisher := r.StartBuild(options)
buildFinishedArgs := &core.BuildFinishedArgs{Box: nil, Result: "failed"}
defer buildFinisher.Finish(buildFinishedArgs)
// Debug information
DumpOptions(options)
// Do some sanity checks before starting
err = dockerlocal.RequireDockerEndpoint(dockerOptions)
if err != nil {
return nil, soft.Exit(err)
}
// Start copying code
logger.Println(f.Info("Executing pipeline"))
timer.Reset()
_, err = r.EnsureCode()
if err != nil {
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
return nil, soft.Exit(err)
}
err = r.CleanupOldBuilds()
if err != nil {
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
}
if options.Verbose {
logger.Printf(f.Success("Copied working dir", timer.String()))
}
// Setup environment is still a fairly special step, it needs
// to start our boxes and get everything set up
logger.Println(f.Info("Running step", "setup environment"))
timer.Reset()
shared, err := r.SetupEnvironment(cmdCtx)
if shared.box != nil {
if options.ShouldRemove {
defer shared.box.Clean()
}
defer shared.box.Stop()
}
if err != nil {
logger.Errorln(f.Fail("Step failed", "setup environment", timer.String()))
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
return nil, soft.Exit(err)
}
if options.Verbose {
logger.Printf(f.Success("Step passed", "setup environment", timer.String()))
}
// Expand our context object
box := shared.box
buildFinishedArgs.Box = box
pipeline := shared.pipeline
repoName := pipeline.DockerRepo()
tag := pipeline.DockerTag()
message := pipeline.DockerMessage()
shouldStore := options.ShouldArtifacts
// TODO(termie): hack for now, probably can be made into a naive class
var storeStep core.Step
if shouldStore {
storeStep = &core.ExternalStep{
//.........这里部分代码省略.........
示例6: SetupEnvironment
// SetupEnvironment does a lot of boilerplate legwork and returns a pipeline,
// box, and session. This is a bit of a long method, but it is pretty much
// the entire "Setup Environment" step.
func (p *Runner) SetupEnvironment(runnerCtx context.Context) (*RunnerShared, error) {
shared := &RunnerShared{}
f := &util.Formatter{p.options.GlobalOptions.ShowColors}
timer := util.NewTimer()
sr := &StepResult{
Success: false,
Artifact: nil,
Message: "",
ExitCode: 1,
}
setupEnvironmentStep := &core.ExternalStep{
BaseStep: core.NewBaseStep(core.BaseStepOptions{
Name: "setup environment",
Owner: "wercker",
Version: util.Version(),
}),
}
finisher := p.StartStep(shared, setupEnvironmentStep, 2)
defer finisher.Finish(sr)
if p.options.Verbose {
p.emitter.Emit(core.Logs, &core.LogsArgs{
Logs: fmt.Sprintf("Running wercker version: %s\n", util.FullVersion()),
})
}
p.logger.Debugln("Application:", p.options.ApplicationName)
// Grab our config
rawConfig, stringConfig, err := p.GetConfig()
if err != nil {
sr.Message = err.Error()
return shared, err
}
shared.config = rawConfig
sr.WerckerYamlContents = stringConfig
// Init the pipeline
pipeline, err := p.GetPipeline(rawConfig)
if err != nil {
sr.Message = err.Error()
return shared, err
}
pipeline.InitEnv(p.options.HostEnv)
shared.pipeline = pipeline
if p.options.Verbose {
p.emitter.Emit(core.Logs, &core.LogsArgs{
Logs: fmt.Sprintf("Using config:\n%s\n", stringConfig),
})
}
// Fetch the box
timer.Reset()
box := pipeline.Box()
_, err = box.Fetch(runnerCtx, pipeline.Env())
if err != nil {
sr.Message = err.Error()
return shared, err
}
// TODO(termie): dump some logs about the image
shared.box = box
if p.options.Verbose {
p.logger.Printf(f.Success(fmt.Sprintf("Fetched %s", box.GetName()), timer.String()))
}
// Fetch the services and add them to the box
if err := p.AddServices(runnerCtx, pipeline, box); err != nil {
sr.Message = err.Error()
return shared, err
}
// Start setting up the pipeline dir
p.logger.Debugln("Copying source to build directory")
err = p.CopySource()
if err != nil {
sr.Message = err.Error()
return shared, err
}
// ... and the cache dir
p.logger.Debugln("Copying cache to build directory")
err = p.CopyCache()
if err != nil {
sr.Message = err.Error()
return shared, err
}
p.logger.Debugln("Steps:", len(pipeline.Steps()))
// Fetch the steps
steps := pipeline.Steps()
for _, step := range steps {
timer.Reset()
if _, err := step.Fetch(); err != nil {
//.........这里部分代码省略.........