Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package wrapper | |
| 6 | |
| 7 import ( | |
| 8 "golang.org/x/net/context" | |
| 9 | |
| 10 "appengine/taskqueue" | |
| 11 ) | |
| 12 | |
| 13 // TQSingleReadWriter allows you to add or delete a single Task from a queue. | |
| 14 // See appengine.taskqueue. | |
| 15 type TQSingleReadWriter interface { | |
| 16 Add(task *taskqueue.Task, queueName string) (*taskqueue.Task, error) | |
| 17 Delete(task *taskqueue.Task, queueName string) error | |
| 18 } | |
| 19 | |
| 20 // TQMultiReadWriter allows you to add or delete abatch of Tasks from a queue. | |
|
Vadim Sh.
2015/05/24 19:01:57
typo: abatch
iannucci
2015/05/24 20:04:32
done
iannucci
2015/05/24 20:04:32
done
| |
| 21 // See appengine.taskqueue. | |
| 22 type TQMultiReadWriter interface { | |
| 23 TQSingleReadWriter | |
| 24 | |
| 25 AddMulti(tasks []*taskqueue.Task, queueName string) ([]*taskqueue.Task, error) | |
| 26 DeleteMulti(tasks []*taskqueue.Task, queueName string) error | |
| 27 } | |
| 28 | |
| 29 // TQLeaser allows you to lease tasks from a Pull queue. | |
| 30 // See appengine.taskqueue. | |
| 31 type TQLeaser interface { | |
| 32 Lease(maxTasks int, queueName string, leaseTime int) ([]*taskqueue.Task, error) | |
| 33 LeaseByTag(maxTasks int, queueName string, leaseTime int, tag string) ([ ]*taskqueue.Task, error) | |
| 34 ModifyLease(task *taskqueue.Task, queueName string, leaseTime int) error | |
| 35 } | |
| 36 | |
| 37 // TQPurger allows you to drain a queue without processing it. See | |
| 38 // appengine.taskqueue. | |
| 39 type TQPurger interface { | |
| 40 Purge(queueName string) error | |
| 41 } | |
| 42 | |
| 43 // TQStatter allows you to obtain semi-realtime stats on the current state of | |
| 44 // a queue. See appengine.taskqueue. | |
| 45 type TQStatter interface { | |
| 46 QueueStats(queueNames []string, maxTasks int) ([]taskqueue.QueueStatisti cs, error) | |
| 47 } | |
| 48 | |
| 49 // TaskQueue is the full interface to the Task Queue service. | |
| 50 type TaskQueue interface { | |
| 51 TQMultiReadWriter | |
| 52 TQLeaser | |
| 53 TQPurger | |
| 54 } | |
| 55 | |
| 56 // TQFactory is the function signature for factory methods compatible with | |
| 57 // SetTQFactory. | |
| 58 type TQFactory func(context.Context) TaskQueue | |
| 59 | |
| 60 // GetTQ gets the TaskQueue implementation from context. | |
| 61 func GetTQ(c context.Context) TaskQueue { | |
| 62 obj := c.Value(taskQueueKey) | |
| 63 if obj == nil || obj.(TQFactory) == nil { | |
| 64 return nil | |
| 65 } | |
| 66 return obj.(TQFactory)(c) | |
| 67 } | |
| 68 | |
| 69 // SetTQFactory sets the function to produce TaskQueue instances, as returned by | |
| 70 // the GetTQ method. | |
| 71 func SetTQFactory(c context.Context, tqf TQFactory) context.Context { | |
| 72 return context.WithValue(c, taskQueueKey, tqf) | |
| 73 } | |
| 74 | |
| 75 // SetTQ sets the current TaskQueue object in the context. Useful for testing | |
| 76 // with a quick mock. This is just a shorthand SetTQFactory invocation to set | |
| 77 // a factory which always returns the same object. | |
| 78 func SetTQ(c context.Context, tq TaskQueue) context.Context { | |
| 79 return SetTQFactory(c, func(context.Context) TaskQueue { return tq }) | |
| 80 } | |
| OLD | NEW |