Skip to content
Snippets Groups Projects
Unverified Commit c8c82b32 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Add "info" command

parent cf673a22
No related branches found
No related tags found
No related merge requests found
...@@ -91,3 +91,7 @@ func (b *buildsHelper) removeBuild(deleteBuild *common.Build) bool { ...@@ -91,3 +91,7 @@ func (b *buildsHelper) removeBuild(deleteBuild *common.Build) bool {
} }
return false return false
} }
func (b *buildsHelper) buildsCount() int {
return len(b.builds)
}
package commands
import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
)
type InfoData struct {
BuildsCount int `json:"builds_count"`
RunnersBuildsCounts map[string]int `json:"runners_builds_counts"`
VersionInfo common.AppVersionInfo `json:"version_info"`
}
type InfoCommand struct {
buildsHelper buildsHelper
data InfoData
}
func (c *InfoCommand) prepare() {
c.data.BuildsCount = c.buildsHelper.buildsCount()
c.data.VersionInfo = common.AppVersion
runnersBuildsCounts := map[string]int{}
for token, count := range c.buildsHelper.counts {
runnersBuildsCounts[helpers.ShortenToken(token)] = count
}
c.data.RunnersBuildsCounts = runnersBuildsCounts
}
func (c *InfoCommand) Execute(context *cli.Context) {
c.prepare()
bytes, err := json.Marshal(c.data)
if err != nil {
log.WithError(err).Errorln("Error with InfoData marshalling to JSON")
return
}
fmt.Print(string(bytes))
}
func init() {
common.RegisterCommand2("info", "show statistic and debuging data", &InfoCommand{})
}
...@@ -56,7 +56,7 @@ type RunCommand struct { ...@@ -56,7 +56,7 @@ type RunCommand struct {
} }
func (mr *RunCommand) log() *log.Entry { func (mr *RunCommand) log() *log.Entry {
return log.WithField("builds", len(mr.buildsHelper.builds)) return log.WithField("builds", mr.buildsHelper.buildsCount())
} }
func (mr *RunCommand) feedRunner(runner *common.RunnerConfig, runners chan *common.RunnerConfig) { func (mr *RunCommand) feedRunner(runner *common.RunnerConfig, runners chan *common.RunnerConfig) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment