Beispiel #1
0
func helpPrinter(w io.Writer, templ string, data interface{}) {
	cliHelpPrinter(w, templ, data)

	fmt.Fprintf(w, providerHelpHeader)

	margin := 4
	maxLen := 0

	backend.EachBackend(func(b *backend.Backend) {
		for itemKey := range b.ProviderHelp {
			if len(itemKey) > maxLen {
				maxLen = len(itemKey)
			}
		}
	})

	itemFmt := fmt.Sprintf("%%%ds - %%s\n", maxLen+margin)

	backend.EachBackend(func(b *backend.Backend) {
		fmt.Fprintf(w, "\n%s provider help:\n\n", b.HumanReadableName)

		sortedKeys := []string{}
		for key := range b.ProviderHelp {
			sortedKeys = append(sortedKeys, key)
		}

		sort.Strings(sortedKeys)

		for _, key := range sortedKeys {
			fmt.Printf(itemFmt, key, b.ProviderHelp[key])
		}
	})

	fmt.Println("")
}
Beispiel #2
0
func workWithBackendProviderCommands(queueType string, flags []cli.Flag) []cli.Command {
	config.DefaultConfig.QueueType = queueType
	commands := []cli.Command{}

	backend.EachBackend(func(b *backend.Backend) {
		commands = append(commands, cli.Command{
			Name:    b.Alias,
			Aliases: []string{string(b.Alias[0])},
			Usage:   fmt.Sprintf("Work with queue type of %q and backend of %q", queueType, b.Alias),
			Flags:   append(b.Flags, flags...),
			Action: func(c *cli.Context) {
				config.DefaultConfig.ProviderName = b.Alias
				runWorker(c)
			},
		})
	})

	return commands
}
Beispiel #3
0
func listBackendProviders(c *cli.Context) {
	backend.EachBackend(func(b *backend.Backend) {
		fmt.Println(b.Alias)
	})
}
Beispiel #4
0
// Setup runs one-time preparatory actions and returns a boolean success value
// that is used to determine if it is safe to invoke the Run func
func (i *CLI) Setup() (bool, error) {
	if i.c.String("pprof-port") != "" {
		// Start net/http/pprof server
		go func() {
			http.ListenAndServe(fmt.Sprintf("localhost:%s", i.c.String("pprof-port")), nil)
		}()
	}

	if i.c.Bool("debug") {
		logrus.SetLevel(logrus.DebugLevel)
	}

	ctx, cancel := gocontext.WithCancel(gocontext.Background())
	logger := context.LoggerFromContext(ctx)

	i.ctx = ctx
	i.cancel = cancel
	i.logger = logger

	logrus.SetFormatter(&logrus.TextFormatter{DisableColors: true})

	cfg := config.FromCLIContext(i.c)
	i.Config = cfg

	if i.c.Bool("echo-config") {
		config.WriteEnvConfig(cfg, os.Stdout)
		return false, nil
	}

	if i.c.Bool("list-backend-providers") {
		backend.EachBackend(func(b *backend.Backend) {
			fmt.Println(b.Alias)
		})
		return false, nil
	}

	logger.WithFields(logrus.Fields{
		"cfg": fmt.Sprintf("%#v", cfg),
	}).Debug("read config")

	i.setupSentry()
	i.setupMetrics()

	err := i.setupJobQueueAndCanceller()
	if err != nil {
		logger.WithField("err", err).Error("couldn't create job queue and canceller")
		return false, err
	}

	generator := NewBuildScriptGenerator(cfg)
	logger.WithFields(logrus.Fields{
		"build_script_generator": fmt.Sprintf("%#v", generator),
	}).Debug("built")

	i.BuildScriptGenerator = generator

	provider, err := backend.NewBackendProvider(cfg.ProviderName, cfg.ProviderConfig)
	if err != nil {
		logger.WithField("err", err).Error("couldn't create backend provider")
		return false, err
	}

	err = provider.Setup(ctx)
	if err != nil {
		logger.WithField("err", err).Error("couldn't setup backend provider")
		return false, err
	}

	logger.WithFields(logrus.Fields{
		"provider": fmt.Sprintf("%#v", provider),
	}).Debug("built")

	i.BackendProvider = provider

	ppc := &ProcessorPoolConfig{
		Hostname:            cfg.Hostname,
		Context:             ctx,
		HardTimeout:         cfg.HardTimeout,
		LogTimeout:          cfg.LogTimeout,
		ScriptUploadTimeout: cfg.ScriptUploadTimeout,
		StartupTimeout:      cfg.StartupTimeout,
	}

	pool := NewProcessorPool(ppc, i.BackendProvider, i.BuildScriptGenerator, i.Canceller)

	pool.SkipShutdownOnLogTimeout = cfg.SkipShutdownOnLogTimeout
	logger.WithFields(logrus.Fields{
		"pool": pool,
	}).Debug("built")

	i.ProcessorPool = pool

	return true, nil
}