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

Side by Side Diff: impl/memory/taskqueue_data.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: stringSet everywhere Created 5 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
« no previous file with comments | « impl/memory/stringset.go ('k') | impl/memory/testing_utils_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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "net/http" 10 "net/http"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 queueName, err := t.getQueueNameLocked(queueName) 120 queueName, err := t.getQueueNameLocked(queueName)
121 if err != nil { 121 if err != nil {
122 return err 122 return err
123 } 123 }
124 124
125 t.named[queueName] = map[string]*tq.Task{} 125 t.named[queueName] = map[string]*tq.Task{}
126 t.archived[queueName] = map[string]*tq.Task{} 126 t.archived[queueName] = map[string]*tq.Task{}
127 return nil 127 return nil
128 } 128 }
129 129
130 var tqOkMethods = map[string]struct{}{ 130 var tqOkMethods = stringSet{
131 "GET": {}, 131 "GET": {},
132 "POST": {}, 132 "POST": {},
133 "HEAD": {}, 133 "HEAD": {},
134 "PUT": {}, 134 "PUT": {},
135 "DELETE": {}, 135 "DELETE": {},
136 } 136 }
137 137
138 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu eueName string) (*tq.Task, error) { 138 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu eueName string) (*tq.Task, error) {
139 toSched := task.Duplicate() 139 toSched := task.Duplicate()
140 140
141 if toSched.Path == "" { 141 if toSched.Path == "" {
142 toSched.Path = "/_ah/queue/" + queueName 142 toSched.Path = "/_ah/queue/" + queueName
143 } 143 }
144 144
145 if toSched.ETA.IsZero() { 145 if toSched.ETA.IsZero() {
146 toSched.ETA = clock.Now(c).Add(toSched.Delay) 146 toSched.ETA = clock.Now(c).Add(toSched.Delay)
147 } else if toSched.Delay != 0 { 147 } else if toSched.Delay != 0 {
148 panic("taskqueue: both Delay and ETA are set") 148 panic("taskqueue: both Delay and ETA are set")
149 } 149 }
150 toSched.Delay = 0 150 toSched.Delay = 0
151 151
152 if toSched.Method == "" { 152 if toSched.Method == "" {
153 toSched.Method = "POST" 153 toSched.Method = "POST"
154 } 154 }
155 » if _, ok := tqOkMethods[toSched.Method]; !ok { 155 » if !tqOkMethods.has(toSched.Method) {
156 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho d) 156 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho d)
157 } 157 }
158 if toSched.Method != "POST" && toSched.Method != "PUT" { 158 if toSched.Method != "POST" && toSched.Method != "PUT" {
159 toSched.Payload = nil 159 toSched.Payload = nil
160 } 160 }
161 161
162 if _, ok := toSched.Header[currentNamespace]; !ok { 162 if _, ok := toSched.Header[currentNamespace]; !ok {
163 if ns != "" { 163 if ns != "" {
164 if toSched.Header == nil { 164 if toSched.Header == nil {
165 toSched.Header = http.Header{} 165 toSched.Header = http.Header{}
(...skipping 23 matching lines...) Expand all
189 closed int32 189 closed int32
190 anony tq.AnonymousQueueData 190 anony tq.AnonymousQueueData
191 parent *taskQueueData 191 parent *taskQueueData
192 } 192 }
193 193
194 var _ interface { 194 var _ interface {
195 memContextObj 195 memContextObj
196 tq.Testable 196 tq.Testable
197 } = (*txnTaskQueueData)(nil) 197 } = (*txnTaskQueueData)(nil)
198 198
199 func (t *txnTaskQueueData) canApplyTxn(obj memContextObj) bool { return false } 199 func (t *txnTaskQueueData) canApplyTxn(obj memContextObj) bool { return false }
200 func (t *txnTaskQueueData) applyTxn(context.Context, memContextObj) { panic(" impossible") } 200 func (t *txnTaskQueueData) applyTxn(context.Context, memContextObj) {
201 func (t *txnTaskQueueData) mkTxn(*ds.TransactionOptions) memContextObj { panic(" impossible") } 201 » impossible(fmt.Errorf("cannot apply nested transaction"))
202 }
203 func (t *txnTaskQueueData) mkTxn(*ds.TransactionOptions) memContextObj {
204 » impossible(fmt.Errorf("cannot start nested transaction"))
205 » return nil
206 }
202 207
203 func (t *txnTaskQueueData) endTxn() { 208 func (t *txnTaskQueueData) endTxn() {
204 if atomic.LoadInt32(&t.closed) == 1 { 209 if atomic.LoadInt32(&t.closed) == 1 {
205 panic("cannot end transaction twice") 210 panic("cannot end transaction twice")
206 } 211 }
207 atomic.StoreInt32(&t.closed, 1) 212 atomic.StoreInt32(&t.closed, 1)
208 } 213 }
209 214
210 func (t *txnTaskQueueData) ResetTasks() { 215 func (t *txnTaskQueueData) ResetTasks() {
211 t.Lock() 216 t.Lock()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return t.parent.GetTombstonedTasks() 252 return t.parent.GetTombstonedTasks()
248 } 253 }
249 254
250 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { 255 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData {
251 return t.parent.GetScheduledTasks() 256 return t.parent.GetScheduledTasks()
252 } 257 }
253 258
254 func (t *txnTaskQueueData) CreateQueue(queueName string) { 259 func (t *txnTaskQueueData) CreateQueue(queueName string) {
255 t.parent.CreateQueue(queueName) 260 t.parent.CreateQueue(queueName)
256 } 261 }
OLDNEW
« no previous file with comments | « impl/memory/stringset.go ('k') | impl/memory/testing_utils_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698