| 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 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 | 9 |
| 10 tq "github.com/luci/gae/service/taskqueue" | 10 tq "github.com/luci/gae/service/taskqueue" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 // TQCounter is the counter object for the TaskQueue service. | 13 // TQCounter is the counter object for the TaskQueue service. |
| 14 type TQCounter struct { | 14 type TQCounter struct { |
| 15 AddMulti Entry | 15 AddMulti Entry |
| 16 DeleteMulti Entry | 16 DeleteMulti Entry |
| 17 Lease Entry |
| 18 LeaseByTag Entry |
| 19 ModifyLease Entry |
| 17 Purge Entry | 20 Purge Entry |
| 18 Stats Entry | 21 Stats Entry |
| 19 } | 22 } |
| 20 | 23 |
| 21 type tqCounter struct { | 24 type tqCounter struct { |
| 22 c *TQCounter | 25 c *TQCounter |
| 23 | 26 |
| 24 tq tq.RawInterface | 27 tq tq.RawInterface |
| 25 } | 28 } |
| 26 | 29 |
| 27 var _ tq.RawInterface = (*tqCounter)(nil) | 30 var _ tq.RawInterface = (*tqCounter)(nil) |
| 28 | 31 |
| 29 func (t *tqCounter) AddMulti(tasks []*tq.Task, queueName string, cb tq.RawTaskCB
) error { | 32 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)) | 33 return t.c.AddMulti.up(t.tq.AddMulti(tasks, queueName, cb)) |
| 31 } | 34 } |
| 32 | 35 |
| 33 func (t *tqCounter) DeleteMulti(tasks []*tq.Task, queueName string, cb tq.RawCB)
error { | 36 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)) | 37 return t.c.DeleteMulti.up(t.tq.DeleteMulti(tasks, queueName, cb)) |
| 35 } | 38 } |
| 36 | 39 |
| 40 func (t *tqCounter) Lease(maxTasks int, queueName string, leaseTime int) ([]*tq.
Task, error) { |
| 41 tasks, err := t.tq.Lease(maxTasks, queueName, leaseTime) |
| 42 t.c.Lease.up(err) |
| 43 return tasks, err |
| 44 } |
| 45 |
| 46 func (t *tqCounter) LeaseByTag(maxTasks int, queueName string, leaseTime int, ta
g string) ([]*tq.Task, error) { |
| 47 tasks, err := t.tq.LeaseByTag(maxTasks, queueName, leaseTime, tag) |
| 48 t.c.LeaseByTag.up(err) |
| 49 return tasks, err |
| 50 } |
| 51 |
| 52 func (t *tqCounter) ModifyLease(task *tq.Task, queueName string, leaseTime int)
error { |
| 53 return t.c.ModifyLease.up(t.tq.ModifyLease(task, queueName, leaseTime)) |
| 54 } |
| 55 |
| 37 func (t *tqCounter) Purge(queueName string) error { | 56 func (t *tqCounter) Purge(queueName string) error { |
| 38 return t.c.Purge.up(t.tq.Purge(queueName)) | 57 return t.c.Purge.up(t.tq.Purge(queueName)) |
| 39 } | 58 } |
| 40 | 59 |
| 41 func (t *tqCounter) Stats(queueNames []string, cb tq.RawStatsCB) error { | 60 func (t *tqCounter) Stats(queueNames []string, cb tq.RawStatsCB) error { |
| 42 return t.c.Stats.up(t.tq.Stats(queueNames, cb)) | 61 return t.c.Stats.up(t.tq.Stats(queueNames, cb)) |
| 43 } | 62 } |
| 44 | 63 |
| 45 func (t *tqCounter) GetTestable() tq.Testable { | 64 func (t *tqCounter) GetTestable() tq.Testable { |
| 46 return t.tq.GetTestable() | 65 return t.tq.GetTestable() |
| 47 } | 66 } |
| 48 | 67 |
| 49 // FilterTQ installs a counter TaskQueue filter in the context. | 68 // FilterTQ installs a counter TaskQueue filter in the context. |
| 50 func FilterTQ(c context.Context) (context.Context, *TQCounter) { | 69 func FilterTQ(c context.Context) (context.Context, *TQCounter) { |
| 51 state := &TQCounter{} | 70 state := &TQCounter{} |
| 52 return tq.AddRawFilters(c, func(ic context.Context, tq tq.RawInterface)
tq.RawInterface { | 71 return tq.AddRawFilters(c, func(ic context.Context, tq tq.RawInterface)
tq.RawInterface { |
| 53 return &tqCounter{state, tq} | 72 return &tqCounter{state, tq} |
| 54 }), state | 73 }), state |
| 55 } | 74 } |
| OLD | NEW |