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

Side by Side Diff: build_scheduler/go/db/modified_tasks.go

Issue 2246933002: Add Task DB implementation using a local BoltDB. (Closed) Base URL: https://skia.googlesource.com/buildbot@taskdb-impl-track
Patch Set: 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
OLDNEW
1 package db 1 package db
2 2
3 import ( 3 import (
4 "sort" 4 "sort"
5 "sync" 5 "sync"
6 "time" 6 "time"
7 7
8 "github.com/satori/go.uuid" 8 "github.com/satori/go.uuid"
9 ) 9 )
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 m.mtx.Unlock() 54 m.mtx.Unlock()
55 if !anyLeft { 55 if !anyLeft {
56 break 56 break
57 } 57 }
58 } 58 }
59 } 59 }
60 60
61 // TrackModifiedTask indicates the given Task should be returned from the next 61 // TrackModifiedTask indicates the given Task should be returned from the next
62 // call to GetModifiedTasks from each subscriber. 62 // call to GetModifiedTasks from each subscriber.
63 func (m *ModifiedTasks) TrackModifiedTask(t *Task) { 63 func (m *ModifiedTasks) TrackModifiedTask(t *Task) {
64 m.TrackModifiedTasks([]*Task{t})
65 }
66
67 // TrackModifiedTasks calls TrackModifiedTask on each item.
68 func (m *ModifiedTasks) TrackModifiedTasks(tasks []*Task) {
64 m.mtx.Lock() 69 m.mtx.Lock()
65 defer m.mtx.Unlock() 70 defer m.mtx.Unlock()
66 » // Make a single copy, since GetModifiedTasks also copies. 71 » for _, t := range tasks {
67 » t = t.Copy() 72 » » // Make a single copy, since GetModifiedTasks also copies.
68 » for _, modTasks := range m.tasks { 73 » » t = t.Copy()
69 » » modTasks[t.Id] = t 74 » » for _, modTasks := range m.tasks {
75 » » » modTasks[t.Id] = t
76 » » }
70 } 77 }
71 } 78 }
72 79
73 // See docs for DB interface. 80 // See docs for DB interface.
74 func (m *ModifiedTasks) StartTrackingModifiedTasks() (string, error) { 81 func (m *ModifiedTasks) StartTrackingModifiedTasks() (string, error) {
75 m.mtx.Lock() 82 m.mtx.Lock()
76 defer m.mtx.Unlock() 83 defer m.mtx.Unlock()
77 if len(m.tasks) == 0 { 84 if len(m.tasks) == 0 {
78 // Initialize the data structure and start expiration goroutine. 85 // Initialize the data structure and start expiration goroutine.
79 m.tasks = map[string]map[string]*Task{} 86 m.tasks = map[string]map[string]*Task{}
80 m.expiration = map[string]time.Time{} 87 m.expiration = map[string]time.Time{}
81 go m.clearExpiredSubscribers() 88 go m.clearExpiredSubscribers()
82 } else if len(m.tasks) >= MAX_MODIFIED_BUILDS_USERS { 89 } else if len(m.tasks) >= MAX_MODIFIED_BUILDS_USERS {
83 return "", ErrTooManyUsers 90 return "", ErrTooManyUsers
84 } 91 }
85 id := uuid.NewV5(uuid.NewV1(), uuid.NewV4().String()).String() 92 id := uuid.NewV5(uuid.NewV1(), uuid.NewV4().String()).String()
86 m.tasks[id] = map[string]*Task{} 93 m.tasks[id] = map[string]*Task{}
87 m.expiration[id] = time.Now().Add(MODIFIED_BUILDS_TIMEOUT) 94 m.expiration[id] = time.Now().Add(MODIFIED_BUILDS_TIMEOUT)
88 return id, nil 95 return id, nil
89 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698