| Index: build_scheduler/go/db/db.go
|
| diff --git a/build_scheduler/go/db/db.go b/build_scheduler/go/db/db.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e1867022c2b568c00e52c24ab18296d145fbdba4
|
| --- /dev/null
|
| +++ b/build_scheduler/go/db/db.go
|
| @@ -0,0 +1,68 @@
|
| +package db
|
| +
|
| +import (
|
| + "errors"
|
| + "time"
|
| +
|
| + "go.skia.org/infra/go/buildbucket"
|
| +)
|
| +
|
| +const (
|
| + // Maximum number of simultaneous GetModifiedBuilds users.
|
| + MAX_MODIFIED_BUILDS_USERS = 10
|
| +
|
| + // Expiration for GetModifiedBuilds users.
|
| + MODIFIED_BUILDS_TIMEOUT = 10 * time.Minute
|
| +)
|
| +
|
| +var (
|
| + ErrTooManyUsers = errors.New("Too many users")
|
| + ErrUnknownId = errors.New("Unknown ID")
|
| +)
|
| +
|
| +func IsTooManyUsers(e error) bool {
|
| + return e != nil && e.Error() == ErrTooManyUsers.Error()
|
| +}
|
| +
|
| +func IsUnknownId(e error) bool {
|
| + return e != nil && e.Error() == ErrUnknownId.Error()
|
| +}
|
| +
|
| +type Build struct {
|
| + *buildbucket.Build
|
| + Commits []string
|
| +}
|
| +
|
| +func (b *Build) Copy() *Build {
|
| + commits := make([]string, len(b.Commits))
|
| + copy(commits, b.Commits)
|
| + rv := &Build{
|
| + Build: b.Build.Copy(),
|
| + Commits: commits,
|
| + }
|
| + return rv
|
| +}
|
| +
|
| +type DB interface {
|
| + // Close the [connection to the] DB.
|
| + Close() error
|
| +
|
| + // GetBuildsFromDateRange retrieves all builds which started in the given date range.
|
| + GetBuildsFromDateRange(time.Time, time.Time) ([]*Build, error)
|
| +
|
| + // GetModifiedBuilds returns all builds modified since the last time
|
| + // GetModifiedBuilds was run with the given id.
|
| + GetModifiedBuilds(string) ([]*Build, error)
|
| +
|
| + // PutBuild inserts or updates the Build in the database.
|
| + PutBuild(*Build) error
|
| +
|
| + // PutBuilds inserts or updates the Builds in the database.
|
| + PutBuilds([]*Build) error
|
| +
|
| + // StartTrackingModifiedBuilds initiates tracking of modified builds for
|
| + // the current caller. Returns a unique ID which can be used by the caller
|
| + // to retrieve builds which have been modified since the last query. The ID
|
| + // expires after a period of inactivity.
|
| + StartTrackingModifiedBuilds() (string, error)
|
| +}
|
|
|