mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 18:31:00 +00:00
contemplating nested storage of tasks and statuses
This commit is contained in:
parent
c324d66872
commit
cd18645784
3 changed files with 79 additions and 1 deletions
|
@ -12,13 +12,14 @@ const (
|
||||||
type Build struct {
|
type Build struct {
|
||||||
Number int `json:"number"`
|
Number int `json:"number"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Tasks int `json:"task_count"`
|
|
||||||
Duration int64 `json:"duration"`
|
Duration int64 `json:"duration"`
|
||||||
Started int64 `json:"started_at"`
|
Started int64 `json:"started_at"`
|
||||||
Finished int64 `json:"finished_at"`
|
Finished int64 `json:"finished_at"`
|
||||||
Created int64 `json:"created_at"`
|
Created int64 `json:"created_at"`
|
||||||
Updated int64 `json:"updated_at"`
|
Updated int64 `json:"updated_at"`
|
||||||
|
|
||||||
|
// Tasks int `json:"task_count"`
|
||||||
|
|
||||||
// Commit represents the commit data send in the
|
// Commit represents the commit data send in the
|
||||||
// post-commit hook. This will not be populated when
|
// post-commit hook. This will not be populated when
|
||||||
// a pull requests.
|
// a pull requests.
|
||||||
|
@ -28,6 +29,14 @@ type Build struct {
|
||||||
// in the post-commit hook. This will only be populated
|
// in the post-commit hook. This will only be populated
|
||||||
// when a pull request.
|
// when a pull request.
|
||||||
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
||||||
|
|
||||||
|
// Statuses represents a list of build statuses used
|
||||||
|
// to annotate the build.
|
||||||
|
Statuses []*Status `json:"statuses,omitempty"`
|
||||||
|
|
||||||
|
// Tasks represents a list of build tasks. A build is
|
||||||
|
// comprised of one or many tasks.
|
||||||
|
Tasks []*Task `json:"tasks,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
|
|
|
@ -77,6 +77,9 @@ func (db *DB) BuildLast(repo string) (*common.Build, error) {
|
||||||
func (db *DB) SetBuild(repo string, build *common.Build) error {
|
func (db *DB) SetBuild(repo string, build *common.Build) error {
|
||||||
repokey := []byte(repo)
|
repokey := []byte(repo)
|
||||||
build.Updated = time.Now().UTC().Unix()
|
build.Updated = time.Now().UTC().Unix()
|
||||||
|
if build.Created == 0 {
|
||||||
|
build.Created = build.Updated
|
||||||
|
}
|
||||||
|
|
||||||
return db.Update(func(t *bolt.Tx) error {
|
return db.Update(func(t *bolt.Tx) error {
|
||||||
|
|
||||||
|
@ -155,3 +158,53 @@ func (db *DB) SetStatus(repo string, build int, status *common.Status) error {
|
||||||
return update(t, bucketBuildStatus, key, status)
|
return update(t, bucketBuildStatus, key, status)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Experimental
|
||||||
|
|
||||||
|
func (db *DB) SetBuildState(repo string, build *common.Build) error {
|
||||||
|
key := []byte(repo + "/" + strconv.Itoa(build.Number))
|
||||||
|
|
||||||
|
return db.Update(func(t *bolt.Tx) error {
|
||||||
|
build_ := &common.Build{}
|
||||||
|
err := get(t, bucketBuild, key, build_)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
build_.Updated = time.Now().UTC().Unix()
|
||||||
|
build_.Duration = build.Duration
|
||||||
|
build_.Started = build.Started
|
||||||
|
build_.Finished = build.Finished
|
||||||
|
build_.State = build.State
|
||||||
|
return update(t, bucketBuild, key, build_)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) SetBuildStatus(repo string, build int, status *common.Status) error {
|
||||||
|
key := []byte(repo + "/" + strconv.Itoa(build))
|
||||||
|
|
||||||
|
return db.Update(func(t *bolt.Tx) error {
|
||||||
|
build_ := &common.Build{}
|
||||||
|
err := get(t, bucketBuild, key, build_)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
build_.Updated = time.Now().UTC().Unix()
|
||||||
|
build_.Statuses = append(build_.Statuses, status)
|
||||||
|
return update(t, bucketBuild, key, build_)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
|
||||||
|
key := []byte(repo + "/" + strconv.Itoa(build))
|
||||||
|
|
||||||
|
return db.Update(func(t *bolt.Tx) error {
|
||||||
|
build_ := &common.Build{}
|
||||||
|
err := get(t, bucketBuild, key, build_)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
build_.Updated = time.Now().UTC().Unix()
|
||||||
|
build_.Tasks[task.Number] = task // TODO check index to prevent nil pointer / panic
|
||||||
|
return update(t, bucketBuild, key, build_)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -138,4 +138,20 @@ type Datastore interface {
|
||||||
// SetLogs inserts or updates a task logs for the
|
// SetLogs inserts or updates a task logs for the
|
||||||
// named repository and build number.
|
// named repository and build number.
|
||||||
SetLogs(string, int, int, []byte) error
|
SetLogs(string, int, int, []byte) error
|
||||||
|
|
||||||
|
// Experimental
|
||||||
|
|
||||||
|
// SetBuildState updates an existing build's start time,
|
||||||
|
// finish time, duration and state. No other fields are
|
||||||
|
// updated.
|
||||||
|
SetBuildState(string, *common.Build) error
|
||||||
|
|
||||||
|
// SetBuildStatus appends a new build status to an
|
||||||
|
// existing build record.
|
||||||
|
SetBuildStatus(string, int, *common.Status) error
|
||||||
|
|
||||||
|
// SetBuildTask updates an existing build task. The build
|
||||||
|
// and task must already exist. If the task does not exist
|
||||||
|
// an error is returned.
|
||||||
|
SetBuildTask(string, int, *common.Task) error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue