| OLD | NEW |
| 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" | |
| 9 "net/http" | 8 "net/http" |
| 10 "regexp" | 9 "regexp" |
| 11 | 10 |
| 12 "golang.org/x/net/context" | 11 "golang.org/x/net/context" |
| 13 | 12 |
| 14 "github.com/luci/gae" | |
| 15 "github.com/luci/gae/impl/dummy" | 13 "github.com/luci/gae/impl/dummy" |
| 16 tq "github.com/luci/gae/service/taskqueue" | 14 tq "github.com/luci/gae/service/taskqueue" |
| 15 "github.com/luci/luci-go/common/errors" |
| 17 "github.com/luci/luci-go/common/mathrand" | 16 "github.com/luci/luci-go/common/mathrand" |
| 18 ) | 17 ) |
| 19 | 18 |
| 20 /////////////////////////////// public functions /////////////////////////////// | 19 /////////////////////////////// public functions /////////////////////////////// |
| 21 | 20 |
| 22 func useTQ(c context.Context) context.Context { | 21 func useTQ(c context.Context) context.Context { |
| 23 return tq.SetFactory(c, func(ic context.Context) tq.Interface { | 22 return tq.SetFactory(c, func(ic context.Context) tq.Interface { |
| 24 tqd := cur(ic).Get(memContextTQIdx) | 23 tqd := cur(ic).Get(memContextTQIdx) |
| 25 if x, ok := tqd.(*taskQueueData); ok { | 24 if x, ok := tqd.(*taskQueueData); ok { |
| 26 return &taskqueueImpl{ | 25 return &taskqueueImpl{ |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 name[i] = validTaskChars[mathrand.Get(c).Intn(len(validT
askChars))] | 201 name[i] = validTaskChars[mathrand.Get(c).Intn(len(validT
askChars))] |
| 203 } | 202 } |
| 204 cur = string(name[:]) | 203 cur = string(name[:]) |
| 205 _, ok = queue[cur] | 204 _, ok = queue[cur] |
| 206 } | 205 } |
| 207 return cur | 206 return cur |
| 208 } | 207 } |
| 209 | 208 |
| 210 func multi(tasks []*tq.Task, queueName string, f func(*tq.Task, string) (*tq.Tas
k, error)) ([]*tq.Task, error) { | 209 func multi(tasks []*tq.Task, queueName string, f func(*tq.Task, string) (*tq.Tas
k, error)) ([]*tq.Task, error) { |
| 211 ret := []*tq.Task(nil) | 210 ret := []*tq.Task(nil) |
| 212 » lme := gae.LazyMultiError{Size: len(tasks)} | 211 » lme := errors.LazyMultiError{Size: len(tasks)} |
| 213 for i, task := range tasks { | 212 for i, task := range tasks { |
| 214 rt, err := f(task, queueName) | 213 rt, err := f(task, queueName) |
| 215 ret = append(ret, rt) | 214 ret = append(ret, rt) |
| 216 lme.Assign(i, err) | 215 lme.Assign(i, err) |
| 217 } | 216 } |
| 218 return ret, lme.Get() | 217 return ret, lme.Get() |
| 219 } | 218 } |
| 220 | 219 |
| 221 func dupTask(t *tq.Task) *tq.Task { | 220 func dupTask(t *tq.Task) *tq.Task { |
| 222 ret := &tq.Task{} | 221 ret := &tq.Task{} |
| (...skipping 24 matching lines...) Expand all Loading... |
| 247 func dupQueue(q tq.QueueData) tq.QueueData { | 246 func dupQueue(q tq.QueueData) tq.QueueData { |
| 248 r := make(tq.QueueData, len(q)) | 247 r := make(tq.QueueData, len(q)) |
| 249 for k, q := range q { | 248 for k, q := range q { |
| 250 r[k] = make(map[string]*tq.Task, len(q)) | 249 r[k] = make(map[string]*tq.Task, len(q)) |
| 251 for tn, t := range q { | 250 for tn, t := range q { |
| 252 r[k][tn] = dupTask(t) | 251 r[k][tn] = dupTask(t) |
| 253 } | 252 } |
| 254 } | 253 } |
| 255 return r | 254 return r |
| 256 } | 255 } |
| OLD | NEW |