1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-02-16 18:34:28 +02:00

37 lines
752 B
Go
Raw Normal View History

package builtin
import (
"database/sql"
2015-06-13 17:37:36 -07:00
"github.com/drone/drone/pkg/types"
)
type Agentstore struct {
*sql.DB
}
func NewAgentstore(db *sql.DB) *Agentstore {
return &Agentstore{db}
}
// Agent returns an agent by ID.
func (db *Agentstore) Agent(build *types.Build) (string, error) {
agent, err := getAgent(db, rebind(stmtAgentSelectAgentCommit), build.ID)
2015-06-13 17:37:36 -07:00
if err != nil {
return "", err
}
return agent.Addr, nil
}
// SetAgent updates an agent in the datastore.
func (db *Agentstore) SetAgent(build *types.Build, addr string) error {
agent := Agent{Addr: addr, BuildID: build.ID}
2015-06-13 17:37:36 -07:00
return createAgent(db, rebind(stmtAgentInsert), &agent)
}
2015-06-13 17:37:36 -07:00
type Agent struct {
ID int64
Addr string
BuildID int64 `sql:"unique:ux_agent_build"`
}