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 Builder string |
| 34 Commits []string |
| 35 Revision string |
| 36 } |
| 37 |
| 38 func (b *Build) Copy() *Build { |
| 39 commits := make([]string, len(b.Commits)) |
| 40 copy(commits, b.Commits) |
| 41 rv := &Build{ |
| 42 Build: b.Build.Copy(), |
| 43 Builder: b.Builder, |
| 44 Commits: commits, |
| 45 Revision: b.Revision, |
| 46 } |
| 47 return rv |
| 48 } |
| 49 |
| 50 type DB interface { |
| 51 // Close the [connection to the] DB. |
| 52 Close() error |
| 53 |
| 54 // GetBuildsFromDateRange retrieves all builds which started in the give
n date range. |
| 55 GetBuildsFromDateRange(time.Time, time.Time) ([]*Build, error) |
| 56 |
| 57 // GetModifiedBuilds returns all builds modified since the last time |
| 58 // GetModifiedBuilds was run with the given id. |
| 59 GetModifiedBuilds(string) ([]*Build, error) |
| 60 |
| 61 // PutBuild inserts or updates the Build in the database. |
| 62 PutBuild(*Build) error |
| 63 |
| 64 // PutBuilds inserts or updates the Builds in the database. |
| 65 PutBuilds([]*Build) error |
| 66 |
| 67 // StartTrackingModifiedBuilds initiates tracking of modified builds for |
| 68 // the current caller. Returns a unique ID which can be used by the call
er |
| 69 // to retrieve builds which have been modified since the last query. The
ID |
| 70 // expires after a period of inactivity. |
| 71 StartTrackingModifiedBuilds() (string, error) |
| 72 } |
OLD | NEW |