Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: taskqueue.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service_test.go ('k') | taskqueue_testable.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: taskqueue.go
diff --git a/taskqueue.go b/taskqueue.go
deleted file mode 100644
index 4af6d22e332a288d6b2b1d7fb5f69cbca146c3d8..0000000000000000000000000000000000000000
--- a/taskqueue.go
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package gae
-
-import (
- "golang.org/x/net/context"
-)
-
-// TaskQueue is the full interface to the Task Queue service.
-type TaskQueue interface {
- Add(task *TQTask, queueName string) (*TQTask, error)
- Delete(task *TQTask, queueName string) error
-
- AddMulti(tasks []*TQTask, queueName string) ([]*TQTask, error)
- DeleteMulti(tasks []*TQTask, queueName string) error
-
- Lease(maxTasks int, queueName string, leaseTime int) ([]*TQTask, error)
- LeaseByTag(maxTasks int, queueName string, leaseTime int, tag string) ([]*TQTask, error)
- ModifyLease(task *TQTask, queueName string, leaseTime int) error
-
- Purge(queueName string) error
-
- QueueStats(queueNames []string) ([]TQStatistics, error)
-}
-
-// TQFactory is the function signature for factory methods compatible with
-// SetTQFactory.
-type TQFactory func(context.Context) TaskQueue
-
-// TQFilter is the function signature for a filter TQ implementation. It
-// gets the current TQ implementation, and returns a new TQ implementation
-// backed by the one passed in.
-type TQFilter func(context.Context, TaskQueue) TaskQueue
-
-// GetTQUnfiltered gets gets the TaskQueue implementation from context without
-// any of the filters applied.
-func GetTQUnfiltered(c context.Context) TaskQueue {
- if f, ok := c.Value(taskQueueKey).(TQFactory); ok && f != nil {
- return f(c)
- }
- return nil
-}
-
-// GetTQ gets the TaskQueue implementation from context.
-func GetTQ(c context.Context) TaskQueue {
- ret := GetTQUnfiltered(c)
- if ret == nil {
- return nil
- }
- for _, f := range getCurTQFilters(c) {
- ret = f(c, ret)
- }
- return ret
-}
-
-// SetTQFactory sets the function to produce TaskQueue instances, as returned by
-// the GetTQ method.
-func SetTQFactory(c context.Context, tqf TQFactory) context.Context {
- return context.WithValue(c, taskQueueKey, tqf)
-}
-
-// SetTQ sets the current TaskQueue object in the context. Useful for testing
-// with a quick mock. This is just a shorthand SetTQFactory invocation to set
-// a factory which always returns the same object.
-func SetTQ(c context.Context, tq TaskQueue) context.Context {
- return SetTQFactory(c, func(context.Context) TaskQueue { return tq })
-}
-
-func getCurTQFilters(c context.Context) []TQFilter {
- curFiltsI := c.Value(taskQueueFilterKey)
- if curFiltsI != nil {
- return curFiltsI.([]TQFilter)
- }
- return nil
-}
-
-// AddTQFilters adds TaskQueue filters to the context.
-func AddTQFilters(c context.Context, filts ...TQFilter) context.Context {
- if len(filts) == 0 {
- return c
- }
- cur := getCurTQFilters(c)
- newFilts := make([]TQFilter, 0, len(cur)+len(filts))
- newFilts = append(newFilts, getCurTQFilters(c)...)
- newFilts = append(newFilts, filts...)
- return context.WithValue(c, taskQueueFilterKey, newFilts)
-}
« no previous file with comments | « service_test.go ('k') | taskqueue_testable.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698