OLD | NEW |
(Empty) | |
| 1 package db |
| 2 |
| 3 import ( |
| 4 "errors" |
| 5 "time" |
| 6 |
| 7 "go.skia.org/infra/go/buildbucket" |
| 8 ) |
| 9 |
| 10 const ( |
| 11 // Maximum number of simultaneous GetModifiedBuilds users. |
| 12 MAX_MODIFIED_BUILDS_USERS = 10 |
| 13 |
| 14 // Expiration for GetModifiedBuilds users. |
| 15 MODIFIED_BUILDS_TIMEOUT = 10 * time.Minute |
| 16 ) |
| 17 |
| 18 var ( |
| 19 ErrTooManyUsers = errors.New("Too many users") |
| 20 ErrUnknownId = errors.New("Unknown ID") |
| 21 ) |
| 22 |
| 23 func IsTooManyUsers(e error) bool { |
| 24 return e != nil && e.Error() == ErrTooManyUsers.Error() |
| 25 } |
| 26 |
| 27 func IsUnknownId(e error) bool { |
| 28 return e != nil && e.Error() == ErrUnknownId.Error() |
| 29 } |
| 30 |
| 31 type Build struct { |
| 32 *buildbucket.Build |
| 33 Commits []string |
| 34 } |
| 35 |
| 36 func (b *Build) Copy() *Build { |
| 37 commits := make([]string, len(b.Commits)) |
| 38 copy(commits, b.Commits) |
| 39 rv := &Build{ |
| 40 Build: b.Build.Copy(), |
| 41 Commits: commits, |
| 42 } |
| 43 return rv |
| 44 } |
| 45 |
| 46 type DB interface { |
| 47 // Close the [connection to the] DB. |
| 48 Close() error |
| 49 |
| 50 // GetBuildsFromDateRange retrieves all builds which started in the give
n date range. |
| 51 GetBuildsFromDateRange(time.Time, time.Time) ([]*Build, error) |
| 52 |
| 53 // GetModifiedBuilds returns all builds modified since the last time |
| 54 // GetModifiedBuilds was run with the given id. |
| 55 GetModifiedBuilds(string) ([]*Build, error) |
| 56 |
| 57 // PutBuild inserts or updates the Build in the database. |
| 58 PutBuild(*Build) error |
| 59 |
| 60 // PutBuilds inserts or updates the Builds in the database. |
| 61 PutBuilds([]*Build) error |
| 62 |
| 63 // StartTrackingModifiedBuilds initiates tracking of modified builds for |
| 64 // the current caller. Returns a unique ID which can be used by the call
er |
| 65 // to retrieve builds which have been modified since the last query. The
ID |
| 66 // expires after a period of inactivity. |
| 67 StartTrackingModifiedBuilds() (string, error) |
| 68 } |
OLD | NEW |