| 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 taskqueue | 5 package taskqueue |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "github.com/luci/luci-go/common/errors" | 8 "github.com/luci/luci-go/common/errors" |
| 9 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
| 10 ) | 10 ) |
| 11 | 11 |
| 12 type taskqueueImpl struct{ RawInterface } | 12 type taskqueueImpl struct{ RawInterface } |
| 13 | 13 |
| 14 func (t *taskqueueImpl) NewTask(path string) *Task { | 14 func (t *taskqueueImpl) NewTask(path string) *Task { |
| 15 return &Task{Path: path} | 15 return &Task{Path: path} |
| 16 } | 16 } |
| 17 | 17 |
| 18 func (t *taskqueueImpl) Add(task *Task, queueName string) error { | 18 func (t *taskqueueImpl) Add(task *Task, queueName string) error { |
| 19 return errors.SingleError(t.AddMulti([]*Task{task}, queueName)) | 19 return errors.SingleError(t.AddMulti([]*Task{task}, queueName)) |
| 20 } | 20 } |
| 21 | 21 |
| 22 func (t *taskqueueImpl) Delete(task *Task, queueName string) error { | 22 func (t *taskqueueImpl) Delete(task *Task, queueName string) error { |
| 23 return errors.SingleError(t.DeleteMulti([]*Task{task}, queueName)) | 23 return errors.SingleError(t.DeleteMulti([]*Task{task}, queueName)) |
| 24 } | 24 } |
| 25 | 25 |
| 26 func (t *taskqueueImpl) AddMulti(tasks []*Task, queueName string) error { | 26 func (t *taskqueueImpl) AddMulti(tasks []*Task, queueName string) error { |
| 27 » lme := errors.LazyMultiError{Size: len(tasks)} | 27 » lme := errors.NewLazyMultiError(len(tasks)) |
| 28 i := 0 | 28 i := 0 |
| 29 err := t.RawInterface.AddMulti(tasks, queueName, func(t *Task, err error
) { | 29 err := t.RawInterface.AddMulti(tasks, queueName, func(t *Task, err error
) { |
| 30 if !lme.Assign(i, err) { | 30 if !lme.Assign(i, err) { |
| 31 *tasks[i] = *t | 31 *tasks[i] = *t |
| 32 } | 32 } |
| 33 i++ | 33 i++ |
| 34 }) | 34 }) |
| 35 if err == nil { | 35 if err == nil { |
| 36 err = lme.Get() | 36 err = lme.Get() |
| 37 } | 37 } |
| 38 return err | 38 return err |
| 39 } | 39 } |
| 40 | 40 |
| 41 func (t *taskqueueImpl) DeleteMulti(tasks []*Task, queueName string) error { | 41 func (t *taskqueueImpl) DeleteMulti(tasks []*Task, queueName string) error { |
| 42 » lme := errors.LazyMultiError{Size: len(tasks)} | 42 » lme := errors.NewLazyMultiError(len(tasks)) |
| 43 i := 0 | 43 i := 0 |
| 44 err := t.RawInterface.DeleteMulti(tasks, queueName, func(err error) { | 44 err := t.RawInterface.DeleteMulti(tasks, queueName, func(err error) { |
| 45 lme.Assign(i, err) | 45 lme.Assign(i, err) |
| 46 i++ | 46 i++ |
| 47 }) | 47 }) |
| 48 if err == nil { | 48 if err == nil { |
| 49 err = lme.Get() | 49 err = lme.Get() |
| 50 } | 50 } |
| 51 return err | 51 return err |
| 52 } | 52 } |
| 53 | 53 |
| 54 func (t *taskqueueImpl) Purge(queueName string) error { | 54 func (t *taskqueueImpl) Purge(queueName string) error { |
| 55 return t.RawInterface.Purge(queueName) | 55 return t.RawInterface.Purge(queueName) |
| 56 } | 56 } |
| 57 | 57 |
| 58 func (t *taskqueueImpl) Stats(queueNames ...string) ([]Statistics, error) { | 58 func (t *taskqueueImpl) Stats(queueNames ...string) ([]Statistics, error) { |
| 59 ret := make([]Statistics, len(queueNames)) | 59 ret := make([]Statistics, len(queueNames)) |
| 60 » lme := errors.LazyMultiError{Size: len(queueNames)} | 60 » lme := errors.NewLazyMultiError(len(queueNames)) |
| 61 i := 0 | 61 i := 0 |
| 62 err := t.RawInterface.Stats(queueNames, func(s *Statistics, err error) { | 62 err := t.RawInterface.Stats(queueNames, func(s *Statistics, err error) { |
| 63 if !lme.Assign(i, err) { | 63 if !lme.Assign(i, err) { |
| 64 ret[i] = *s | 64 ret[i] = *s |
| 65 } | 65 } |
| 66 i++ | 66 i++ |
| 67 }) | 67 }) |
| 68 if err == nil { | 68 if err == nil { |
| 69 err = lme.Get() | 69 err = lme.Get() |
| 70 } | 70 } |
| 71 return ret, err | 71 return ret, err |
| 72 } | 72 } |
| 73 | 73 |
| 74 func (t *taskqueueImpl) Raw() RawInterface { | 74 func (t *taskqueueImpl) Raw() RawInterface { |
| 75 return t.RawInterface | 75 return t.RawInterface |
| 76 } | 76 } |
| 77 | 77 |
| 78 func (t *taskqueueImpl) Testable() Testable { | 78 func (t *taskqueueImpl) Testable() Testable { |
| 79 return t.RawInterface.Testable() | 79 return t.RawInterface.Testable() |
| 80 } | 80 } |
| 81 | 81 |
| 82 var _ Interface = (*taskqueueImpl)(nil) | 82 var _ Interface = (*taskqueueImpl)(nil) |
| 83 | 83 |
| 84 func Get(c context.Context) Interface { | 84 func Get(c context.Context) Interface { |
| 85 return &taskqueueImpl{GetRaw(c)} | 85 return &taskqueueImpl{GetRaw(c)} |
| 86 } | 86 } |
| OLD | NEW |