OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package count | 5 package count |
6 | 6 |
7 import ( | 7 import ( |
| 8 "time" |
| 9 |
8 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
9 | 11 |
10 tq "github.com/luci/gae/service/taskqueue" | 12 tq "github.com/luci/gae/service/taskqueue" |
11 ) | 13 ) |
12 | 14 |
13 // TQCounter is the counter object for the TaskQueue service. | 15 // TQCounter is the counter object for the TaskQueue service. |
14 type TQCounter struct { | 16 type TQCounter struct { |
15 AddMulti Entry | 17 AddMulti Entry |
16 DeleteMulti Entry | 18 DeleteMulti Entry |
| 19 Lease Entry |
| 20 LeaseByTag Entry |
| 21 ModifyLease Entry |
17 Purge Entry | 22 Purge Entry |
18 Stats Entry | 23 Stats Entry |
19 } | 24 } |
20 | 25 |
21 type tqCounter struct { | 26 type tqCounter struct { |
22 c *TQCounter | 27 c *TQCounter |
23 | 28 |
24 tq tq.RawInterface | 29 tq tq.RawInterface |
25 } | 30 } |
26 | 31 |
27 var _ tq.RawInterface = (*tqCounter)(nil) | 32 var _ tq.RawInterface = (*tqCounter)(nil) |
28 | 33 |
29 func (t *tqCounter) AddMulti(tasks []*tq.Task, queueName string, cb tq.RawTaskCB
) error { | 34 func (t *tqCounter) AddMulti(tasks []*tq.Task, queueName string, cb tq.RawTaskCB
) error { |
30 return t.c.AddMulti.up(t.tq.AddMulti(tasks, queueName, cb)) | 35 return t.c.AddMulti.up(t.tq.AddMulti(tasks, queueName, cb)) |
31 } | 36 } |
32 | 37 |
33 func (t *tqCounter) DeleteMulti(tasks []*tq.Task, queueName string, cb tq.RawCB)
error { | 38 func (t *tqCounter) DeleteMulti(tasks []*tq.Task, queueName string, cb tq.RawCB)
error { |
34 return t.c.DeleteMulti.up(t.tq.DeleteMulti(tasks, queueName, cb)) | 39 return t.c.DeleteMulti.up(t.tq.DeleteMulti(tasks, queueName, cb)) |
35 } | 40 } |
36 | 41 |
| 42 func (t *tqCounter) Lease(maxTasks int, queueName string, leaseTime time.Duratio
n) ([]*tq.Task, error) { |
| 43 tasks, err := t.tq.Lease(maxTasks, queueName, leaseTime) |
| 44 t.c.Lease.up(err) |
| 45 return tasks, err |
| 46 } |
| 47 |
| 48 func (t *tqCounter) LeaseByTag(maxTasks int, queueName string, leaseTime time.Du
ration, tag string) ([]*tq.Task, error) { |
| 49 tasks, err := t.tq.LeaseByTag(maxTasks, queueName, leaseTime, tag) |
| 50 t.c.LeaseByTag.up(err) |
| 51 return tasks, err |
| 52 } |
| 53 |
| 54 func (t *tqCounter) ModifyLease(task *tq.Task, queueName string, leaseTime time.
Duration) error { |
| 55 return t.c.ModifyLease.up(t.tq.ModifyLease(task, queueName, leaseTime)) |
| 56 } |
| 57 |
37 func (t *tqCounter) Purge(queueName string) error { | 58 func (t *tqCounter) Purge(queueName string) error { |
38 return t.c.Purge.up(t.tq.Purge(queueName)) | 59 return t.c.Purge.up(t.tq.Purge(queueName)) |
39 } | 60 } |
40 | 61 |
41 func (t *tqCounter) Stats(queueNames []string, cb tq.RawStatsCB) error { | 62 func (t *tqCounter) Stats(queueNames []string, cb tq.RawStatsCB) error { |
42 return t.c.Stats.up(t.tq.Stats(queueNames, cb)) | 63 return t.c.Stats.up(t.tq.Stats(queueNames, cb)) |
43 } | 64 } |
44 | 65 |
45 func (t *tqCounter) GetTestable() tq.Testable { | 66 func (t *tqCounter) GetTestable() tq.Testable { |
46 return t.tq.GetTestable() | 67 return t.tq.GetTestable() |
47 } | 68 } |
48 | 69 |
49 // FilterTQ installs a counter TaskQueue filter in the context. | 70 // FilterTQ installs a counter TaskQueue filter in the context. |
50 func FilterTQ(c context.Context) (context.Context, *TQCounter) { | 71 func FilterTQ(c context.Context) (context.Context, *TQCounter) { |
51 state := &TQCounter{} | 72 state := &TQCounter{} |
52 return tq.AddRawFilters(c, func(ic context.Context, tq tq.RawInterface)
tq.RawInterface { | 73 return tq.AddRawFilters(c, func(ic context.Context, tq tq.RawInterface)
tq.RawInterface { |
53 return &tqCounter{state, tq} | 74 return &tqCounter{state, tq} |
54 }), state | 75 }), state |
55 } | 76 } |
OLD | NEW |