Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: build_scheduler/go/db/db.go

Issue 2226583003: Add build scheduler DB interface, dumb in-memory impl, cache (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Address more comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build_scheduler/go/db/cache_test.go ('k') | build_scheduler/go/db/db_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2385dfefb63df71e6602d9d61924b0ad79117698
--- /dev/null
+++ b/build_scheduler/go/db/db.go
@@ -0,0 +1,72 @@
+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
+ Builder string
+ Commits []string
+ Revision string
+}
+
+func (b *Build) Copy() *Build {
+ commits := make([]string, len(b.Commits))
+ copy(commits, b.Commits)
+ rv := &Build{
+ Build: b.Build.Copy(),
+ Builder: b.Builder,
+ Commits: commits,
+ Revision: b.Revision,
+ }
+ 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)
+}
« no previous file with comments | « build_scheduler/go/db/cache_test.go ('k') | build_scheduler/go/db/db_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698