mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
ability to persist agent data
This commit is contained in:
parent
4071ea73a0
commit
ca931cd9eb
5 changed files with 51 additions and 2 deletions
9
common/agent.go
Normal file
9
common/agent.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package common
|
||||
|
||||
// Agent represents a worker that has connected
|
||||
// to the system in order to perform work
|
||||
type Agent struct {
|
||||
Name string
|
||||
Addr string
|
||||
IsHealthy bool
|
||||
}
|
1
datastore/bolt/agent.go
Normal file
1
datastore/bolt/agent.go
Normal file
|
@ -0,0 +1 @@
|
|||
package bolt
|
|
@ -23,6 +23,7 @@ var (
|
|||
bucketRepoParams = []byte("repo_params")
|
||||
bucketRepoUsers = []byte("repo_users")
|
||||
bucketBuild = []byte("build")
|
||||
bucketBuildAgent = []byte("build_agent")
|
||||
bucketBuildStatus = []byte("build_status")
|
||||
bucketBuildLogs = []byte("build_logs")
|
||||
bucketBuildSeq = []byte("build_seq")
|
||||
|
@ -49,6 +50,7 @@ func New(path string) (*DB, error) {
|
|||
tx.CreateBucketIfNotExists(bucketRepoParams)
|
||||
tx.CreateBucketIfNotExists(bucketRepoUsers)
|
||||
tx.CreateBucketIfNotExists(bucketBuild)
|
||||
tx.CreateBucketIfNotExists(bucketBuildAgent)
|
||||
tx.CreateBucketIfNotExists(bucketBuildStatus)
|
||||
tx.CreateBucketIfNotExists(bucketBuildLogs)
|
||||
tx.CreateBucketIfNotExists(bucketBuildSeq)
|
||||
|
|
|
@ -3,10 +3,11 @@ package bolt
|
|||
import (
|
||||
//"bytes"
|
||||
"encoding/binary"
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/drone/drone/common"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/drone/drone/common"
|
||||
)
|
||||
|
||||
// Build gets the specified build number for the
|
||||
|
@ -213,3 +214,27 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
|
|||
})
|
||||
}
|
||||
|
||||
// SetBuildAgent insert or updates the agent that is
|
||||
// running a build.
|
||||
func (db *DB) SetBuildAgent(repo string, build int, agent *common.Agent) error {
|
||||
key := []byte(repo + "/" + strconv.Itoa(build))
|
||||
return db.Update(func(t *bolt.Tx) error {
|
||||
return update(t, bucketBuildAgent, key, agent)
|
||||
})
|
||||
}
|
||||
|
||||
func (db *DB) DelBuildAgent(repo string, build int, agent *common.Agent) error {
|
||||
key := []byte(repo + "/" + strconv.Itoa(build))
|
||||
return db.Update(func(t *bolt.Tx) error {
|
||||
return delete(t, bucketBuildAgent, key)
|
||||
})
|
||||
}
|
||||
|
||||
func (db *DB) BuildAgent(repo string, build int) (*common.Agent, error) {
|
||||
key := []byte(repo + "/" + strconv.Itoa(build))
|
||||
agent := &common.Agent{}
|
||||
err := db.View(func(t *bolt.Tx) error {
|
||||
return get(t, bucketBuildAgent, key, agent)
|
||||
})
|
||||
return agent, err
|
||||
}
|
||||
|
|
|
@ -101,6 +101,10 @@ type Datastore interface {
|
|||
// named repository.
|
||||
BuildLast(string) (*common.Build, error)
|
||||
|
||||
// BuildAgent returns the agent that is being
|
||||
// used to execute the build.
|
||||
// BuildAgent(string, int) (*common.Agent, error)
|
||||
|
||||
// SetBuild inserts or updates a build for the named
|
||||
// repository. The build number is incremented and
|
||||
// assigned to the provided build.
|
||||
|
@ -120,6 +124,14 @@ type Datastore interface {
|
|||
// an error is returned.
|
||||
SetBuildTask(string, int, *common.Task) error
|
||||
|
||||
// SetBuildAgent insert or updates the agent that is
|
||||
// running a build.
|
||||
// SetBuildAgent(string, int, *common.Agent) error
|
||||
|
||||
// DelBuildAgent purges the referce to the agent
|
||||
// that ran a build.
|
||||
// DelBuildAgent(string, int, *common.Agent) error
|
||||
|
||||
// LogReader gets the task logs at index N for
|
||||
// the named repository and build number.
|
||||
LogReader(string, int, int) (io.Reader, error)
|
||||
|
|
Loading…
Reference in a new issue