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

Side by Side Diff: build_scheduler/go/task_scheduler/cache_wrapper.go

Issue 2296763008: [task scheduler] Move files from build_scheduler/ to task_scheduler/ (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 4 years, 3 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
OLDNEW
(Empty)
1 package task_scheduler
2
3 import (
4 "fmt"
5
6 "go.skia.org/infra/build_scheduler/go/db"
7 )
8
9 // cacheWrapper is an implementation of db.TaskCache which allows insertion of
10 // fake Tasks. Use one per task spec.
11 type cacheWrapper struct {
12 byCommit map[string]*db.Task
13 byId map[string]*db.Task
14 c db.TaskCache
15 known bool
16 }
17
18 func newCacheWrapper(c db.TaskCache) *cacheWrapper {
19 return &cacheWrapper{
20 byCommit: map[string]*db.Task{},
21 byId: map[string]*db.Task{},
22 c: c,
23 known: false,
24 }
25 }
26
27 // See documentation for TaskCache interface.
28 func (c *cacheWrapper) GetTask(id string) (*db.Task, error) {
29 if t, ok := c.byId[id]; ok {
30 return t, nil
31 }
32 return c.c.GetTask(id)
33 }
34
35 // See documentation for TaskCache interface.
36 func (c *cacheWrapper) GetTaskForCommit(repo, commit, name string) (*db.Task, er ror) {
37 if t, ok := c.byCommit[commit]; ok {
38 return t, nil
39 }
40 return c.c.GetTaskForCommit(repo, commit, name)
41 }
42
43 // See documentation for TaskCache interface.
44 func (c *cacheWrapper) GetTasksForCommits(string, []string) (map[string]map[stri ng]*db.Task, error) {
45 return nil, fmt.Errorf("cacheWrapper.GetTasksForCommits not implemented. ")
46 }
47
48 // See documentation for TaskCache interface.
49 func (c *cacheWrapper) KnownTaskName(repo, name string) bool {
50 if c.known {
51 return true
52 }
53 return c.c.KnownTaskName(repo, name)
54 }
55
56 // See documentation for TaskCache interface.
57 func (c *cacheWrapper) UnfinishedTasks() ([]*db.Task, error) {
58 return nil, fmt.Errorf("cacheWrapper.UnfinishedTasks not implemented.")
59 }
60
61 // See documentation for TaskCache interface.
62 func (c *cacheWrapper) Update() error {
63 return fmt.Errorf("cacheWrapper.Update not implemented.")
64 }
65
66 // insert adds a task to the cacheWrapper's fake layer so that it will be
67 // included in query results but not actually inserted into the DB.
68 func (c *cacheWrapper) insert(t *db.Task) {
69 c.byId[t.Id] = t
70 for _, commit := range t.Commits {
71 c.byCommit[commit] = t
72 }
73 c.known = true
74 }
OLDNEW
« no previous file with comments | « build_scheduler/go/parse_task_cfg/main.go ('k') | build_scheduler/go/task_scheduler/perftest/perftest.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698