OLD | NEW |
| (Empty) |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | |
2 // Use of this source code is governed under the Apache License, Version 2.0 | |
3 // that can be found in the LICENSE file. | |
4 | |
5 package taskqueue | |
6 | |
7 import ( | |
8 "github.com/luci/luci-go/common/errors" | |
9 ) | |
10 | |
11 type taskqueueImpl struct{ RawInterface } | |
12 | |
13 func (t *taskqueueImpl) Add(task *Task, queueName string) error { | |
14 return errors.SingleError(t.AddMulti([]*Task{task}, queueName)) | |
15 } | |
16 | |
17 func (t *taskqueueImpl) Delete(task *Task, queueName string) error { | |
18 return errors.SingleError(t.DeleteMulti([]*Task{task}, queueName)) | |
19 } | |
20 | |
21 func (t *taskqueueImpl) AddMulti(tasks []*Task, queueName string) error { | |
22 lme := errors.NewLazyMultiError(len(tasks)) | |
23 i := 0 | |
24 err := t.RawInterface.AddMulti(tasks, queueName, func(t *Task, err error
) { | |
25 if !lme.Assign(i, err) { | |
26 *tasks[i] = *t | |
27 } | |
28 i++ | |
29 }) | |
30 if err == nil { | |
31 err = lme.Get() | |
32 } | |
33 return err | |
34 } | |
35 | |
36 func (t *taskqueueImpl) DeleteMulti(tasks []*Task, queueName string) error { | |
37 lme := errors.NewLazyMultiError(len(tasks)) | |
38 i := 0 | |
39 err := t.RawInterface.DeleteMulti(tasks, queueName, func(err error) { | |
40 lme.Assign(i, err) | |
41 i++ | |
42 }) | |
43 if err == nil { | |
44 err = lme.Get() | |
45 } | |
46 return err | |
47 } | |
48 | |
49 func (t *taskqueueImpl) Purge(queueName string) error { | |
50 return t.RawInterface.Purge(queueName) | |
51 } | |
52 | |
53 func (t *taskqueueImpl) Stats(queueNames ...string) ([]Statistics, error) { | |
54 ret := make([]Statistics, len(queueNames)) | |
55 lme := errors.NewLazyMultiError(len(queueNames)) | |
56 i := 0 | |
57 err := t.RawInterface.Stats(queueNames, func(s *Statistics, err error) { | |
58 if !lme.Assign(i, err) { | |
59 ret[i] = *s | |
60 } | |
61 i++ | |
62 }) | |
63 if err == nil { | |
64 err = lme.Get() | |
65 } | |
66 return ret, err | |
67 } | |
68 | |
69 func (t *taskqueueImpl) Raw() RawInterface { | |
70 return t.RawInterface | |
71 } | |
72 | |
73 func (t *taskqueueImpl) Testable() Testable { | |
74 return t.RawInterface.Testable() | |
75 } | |
76 | |
77 var _ Interface = (*taskqueueImpl)(nil) | |
OLD | NEW |