Commit 775b150a authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Default concurrent value is set to number of CPUs

parent cb9c7348
v 0.2.1
v 0.3.0
- Added repo slug to build path
- Build path includes repository hostname
- Support TLS connection with Docker
- Default concurrent limit is set to number of CPUs
v 0.2.0
- Added delete and verify commands
......
......@@ -17,7 +17,7 @@ func runDelete(c *cli.Context) {
log.Fatalln("Failed to delete runner")
}
config := &common.Config{}
config := common.NewConfig()
err := config.LoadConfig(c.String("config"))
if err != nil {
return
......
......@@ -217,14 +217,14 @@ func (mr *MultiRunner) startWorkers(startWorker chan int, stopWorker chan bool,
}
func (mr *MultiRunner) loadConfig() error {
newConfig := common.Config{}
newConfig := common.NewConfig()
err := newConfig.LoadConfig(mr.configFile)
if err != nil {
return err
}
mr.healthy = nil
mr.config = &newConfig
mr.config = newConfig
return nil
}
......
......@@ -18,7 +18,7 @@ import (
type SetupContext struct {
*cli.Context
configFile string
config common.Config
config *common.Config
reader *bufio.Reader
}
......@@ -168,6 +168,7 @@ func (s *SetupContext) askRunner() common.RunnerConfig {
func runSetup(c *cli.Context) {
s := SetupContext{
Context: c,
config: common.NewConfig(),
configFile: c.String("config"),
reader: bufio.NewReader(os.Stdin),
}
......
......@@ -8,7 +8,7 @@ import (
)
func runVerify(c *cli.Context) {
config := &common.Config{}
config := common.NewConfig()
err := config.LoadConfig(c.String("config"))
if err != nil {
log.Fatalln(err)
......
......@@ -11,6 +11,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/ayufan/gitlab-ci-multi-runner/helpers"
"github.com/ayufan/gitlab-ci-multi-runner/ssh"
"runtime"
)
type DockerConfig struct {
......@@ -73,6 +74,14 @@ func (c *RunnerConfig) UniqueID() string {
return c.URL + c.Token
}
func NewConfig() *Config {
return &Config{
BaseConfig: BaseConfig{
Concurrent: runtime.NumCPU(),
},
}
}
func (c *Config) LoadConfig(configFile string) error {
info, err := os.Stat(configFile)
if err != nil {
......@@ -83,10 +92,6 @@ func (c *Config) LoadConfig(configFile string) error {
return err
}
if c.Concurrent == 0 {
c.Concurrent = 1
}
c.ModTime = info.ModTime()
return nil
}
......
package helpers
func IsEmpty(data *string) bool {
return data == nil || *data == ""
}
func StringOrDefault(data *string, def string) string {
if IsEmpty(data) {
return def
} else {
return *data
}
}
func NonZeroOrDefault(data *int, def int) int {
if data == nil || *data <= 0 {
return def
} else {
return *data
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment