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

Side by Side Diff: service/taskqueue/taskqueue.go

Issue 1270063003: Make the rest of the services have a similar raw/user interface structure. (Closed) Base URL: https://github.com/luci/gae.git@add_datastore
Patch Set: Created 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package taskqueue
6
7 import (
8 "github.com/luci/luci-go/common/errors"
9 "golang.org/x/net/context"
10 )
11
12 type taskqueueImpl struct{ RawInterface }
13
14 func (t *taskqueueImpl) NewTask(path string) *Task {
15 return &Task{Path: path}
16 }
17
18 func (t *taskqueueImpl) Add(task *Task, queueName string) error {
19 return errors.SingleError(t.AddMulti([]*Task{task}, queueName))
20 }
21
22 func (t *taskqueueImpl) Delete(task *Task, queueName string) error {
23 return errors.SingleError(t.DeleteMulti([]*Task{task}, queueName))
24 }
25
26 func (t *taskqueueImpl) AddMulti(tasks []*Task, queueName string) error {
27 lme := errors.LazyMultiError{Size: len(tasks)}
28 i := 0
29 err := t.RawInterface.AddMulti(tasks, queueName, func(t *Task, err error ) {
30 if !lme.Assign(i, err) {
31 *tasks[i] = *t
32 }
33 i++
34 })
35 if err == nil {
36 err = lme.Get()
37 }
38 return err
39 }
40
41 func (t *taskqueueImpl) DeleteMulti(tasks []*Task, queueName string) error {
42 lme := errors.LazyMultiError{Size: len(tasks)}
43 i := 0
44 err := t.RawInterface.DeleteMulti(tasks, queueName, func(err error) {
45 lme.Assign(i, err)
46 i++
47 })
48 if err == nil {
49 err = lme.Get()
50 }
51 return err
52 }
53
54 func (t *taskqueueImpl) Purge(queueName string) error {
55 return t.RawInterface.Purge(queueName)
56 }
57
58 func (t *taskqueueImpl) Stats(queueNames ...string) ([]Statistics, error) {
59 ret := make([]Statistics, len(queueNames))
60 lme := errors.LazyMultiError{Size: len(queueNames)}
61 i := 0
dnj 2015/08/03 22:37:25 IMO cleaner to allocate "ret" with zero length and
dnj (Google) 2015/08/04 03:48:03 (Pang)
iannucci 2015/08/04 03:58:33 How would this be cleaner? I still need i for the
dnj 2015/08/04 18:01:16 Oh sorry, I didn't see the "i" being used there. N
62 err := t.RawInterface.Stats(queueNames, func(s *Statistics, err error) {
63 if !lme.Assign(i, err) {
64 ret[i] = *s
65 }
66 i++
67 })
68 if err == nil {
69 err = lme.Get()
70 }
71 return ret, err
72 }
73
74 func (t *taskqueueImpl) Raw() RawInterface {
75 return t.RawInterface
76 }
77
78 var _ Interface = (*taskqueueImpl)(nil)
79
80 func Get(c context.Context) Interface {
81 return &taskqueueImpl{GetRaw(c)}
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698