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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« 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