2015-05-01 04:08:42 +00:00
|
|
|
package builtin
|
2015-05-18 22:47:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
2015-06-14 00:37:36 +00:00
|
|
|
"github.com/drone/drone/pkg/types"
|
2015-05-18 22:47:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Agentstore struct {
|
|
|
|
*sql.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAgentstore(db *sql.DB) *Agentstore {
|
|
|
|
return &Agentstore{db}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Agent returns an agent by ID.
|
2015-06-23 03:45:08 +00:00
|
|
|
func (db *Agentstore) Agent(build *types.Build) (string, error) {
|
|
|
|
agent, err := getAgent(db, rebind(stmtAgentSelectAgentCommit), build.ID)
|
2015-06-14 00:37:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return agent.Addr, nil
|
2015-05-18 22:47:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 03:44:44 +00:00
|
|
|
// SetAgent updates an agent in the datastore.
|
2015-06-23 03:45:08 +00:00
|
|
|
func (db *Agentstore) SetAgent(build *types.Build, addr string) error {
|
|
|
|
agent := Agent{Addr: addr, BuildID: build.ID}
|
2015-06-14 00:37:36 +00:00
|
|
|
return createAgent(db, rebind(stmtAgentInsert), &agent)
|
2015-05-18 22:47:13 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 00:37:36 +00:00
|
|
|
type Agent struct {
|
2015-06-23 03:45:08 +00:00
|
|
|
ID int64
|
|
|
|
Addr string
|
|
|
|
BuildID int64 `sql:"unique:ux_agent_build"`
|
2015-05-18 22:47:13 +00:00
|
|
|
}
|