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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: service/taskqueue/taskqueue.go
diff --git a/service/taskqueue/taskqueue.go b/service/taskqueue/taskqueue.go
new file mode 100644
index 0000000000000000000000000000000000000000..97ab2ffe60d506ccac863e557b157855fb930533
--- /dev/null
+++ b/service/taskqueue/taskqueue.go
@@ -0,0 +1,82 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package taskqueue
+
+import (
+ "github.com/luci/luci-go/common/errors"
+ "golang.org/x/net/context"
+)
+
+type taskqueueImpl struct{ RawInterface }
+
+func (t *taskqueueImpl) NewTask(path string) *Task {
+ return &Task{Path: path}
+}
+
+func (t *taskqueueImpl) Add(task *Task, queueName string) error {
+ return errors.SingleError(t.AddMulti([]*Task{task}, queueName))
+}
+
+func (t *taskqueueImpl) Delete(task *Task, queueName string) error {
+ return errors.SingleError(t.DeleteMulti([]*Task{task}, queueName))
+}
+
+func (t *taskqueueImpl) AddMulti(tasks []*Task, queueName string) error {
+ lme := errors.LazyMultiError{Size: len(tasks)}
+ i := 0
+ err := t.RawInterface.AddMulti(tasks, queueName, func(t *Task, err error) {
+ if !lme.Assign(i, err) {
+ *tasks[i] = *t
+ }
+ i++
+ })
+ if err == nil {
+ err = lme.Get()
+ }
+ return err
+}
+
+func (t *taskqueueImpl) DeleteMulti(tasks []*Task, queueName string) error {
+ lme := errors.LazyMultiError{Size: len(tasks)}
+ i := 0
+ err := t.RawInterface.DeleteMulti(tasks, queueName, func(err error) {
+ lme.Assign(i, err)
+ i++
+ })
+ if err == nil {
+ err = lme.Get()
+ }
+ return err
+}
+
+func (t *taskqueueImpl) Purge(queueName string) error {
+ return t.RawInterface.Purge(queueName)
+}
+
+func (t *taskqueueImpl) Stats(queueNames ...string) ([]Statistics, error) {
+ ret := make([]Statistics, len(queueNames))
+ lme := errors.LazyMultiError{Size: len(queueNames)}
+ 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
+ err := t.RawInterface.Stats(queueNames, func(s *Statistics, err error) {
+ if !lme.Assign(i, err) {
+ ret[i] = *s
+ }
+ i++
+ })
+ if err == nil {
+ err = lme.Get()
+ }
+ return ret, err
+}
+
+func (t *taskqueueImpl) Raw() RawInterface {
+ return t.RawInterface
+}
+
+var _ Interface = (*taskqueueImpl)(nil)
+
+func Get(c context.Context) Interface {
+ return &taskqueueImpl{GetRaw(c)}
+}

Powered by Google App Engine
This is Rietveld 408576698