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

Unified Diff: service/taskqueue/context.go

Issue 1494223002: Add API to allow you to get the non-transactional datastore or taskqueue. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix doc and naming Created 5 years 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/datastore/datastore_test.go ('k') | service/taskqueue/taskqueue.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/taskqueue/context.go
diff --git a/service/taskqueue/context.go b/service/taskqueue/context.go
index 160f6b9d269914abc299267cb26e8055b8c44657..805061ee1781f3754a45a99cea9f8c4b22eccb1f 100644
--- a/service/taskqueue/context.go
+++ b/service/taskqueue/context.go
@@ -16,8 +16,10 @@ var (
)
// RawFactory is the function signature for RawFactory methods compatible with
-// SetRawFactory.
-type RawFactory func(context.Context) RawInterface
+// SetRawFactory. wantTxn is true if the Factory should return the taskqueue in
+// the current transaction, and false if the Factory should return the
+// non-transactional (root) taskqueue service.
+type RawFactory func(c context.Context, wantTxn bool) RawInterface
// RawFilter is the function signature for a RawFilter TQ implementation. It
// gets the current TQ implementation, and returns a new TQ implementation
@@ -26,16 +28,17 @@ type RawFilter func(context.Context, RawInterface) RawInterface
// getUnfiltered gets gets the RawInterface implementation from context without
// any of the filters applied.
-func getUnfiltered(c context.Context) RawInterface {
+func getUnfiltered(c context.Context, wantTxn bool) RawInterface {
if f, ok := c.Value(taskQueueKey).(RawFactory); ok && f != nil {
- return f(c)
+ return f(c, wantTxn)
}
return nil
}
-// GetRaw gets the RawInterface implementation from context.
-func GetRaw(c context.Context) RawInterface {
- ret := getUnfiltered(c)
+// getFiltered gets the taskqueue (transactional or not), and applies all of
+// the currently installed filters to it.
+func getFiltered(c context.Context, wantTxn bool) RawInterface {
+ ret := getUnfiltered(c, wantTxn)
if ret == nil {
return nil
}
@@ -45,6 +48,28 @@ func GetRaw(c context.Context) RawInterface {
return ret
}
+// GetRaw gets the RawInterface implementation from context.
+func GetRaw(c context.Context) RawInterface {
+ return getFiltered(c, true)
+}
+
+// GetRawNoTxn gets the RawInterface implementation from context. If there's a
+// currently active transaction, this will return a non-transactional connection
+// to the taskqueue, otherwise this is the same as GetRaw.
+func GetRawNoTxn(c context.Context) RawInterface {
+ return getFiltered(c, false)
+}
+
+// Get gets the Interface implementation from context.
+func Get(c context.Context) Interface {
+ return &taskqueueImpl{GetRaw(c)}
+}
+
+// GetNoTxn gets the Interface implementation from context.
+func GetNoTxn(c context.Context) Interface {
+ return &taskqueueImpl{GetRawNoTxn(c)}
+}
+
// SetRawFactory sets the function to produce RawInterface instances, as returned by
// the GetRaw method.
func SetRawFactory(c context.Context, tqf RawFactory) context.Context {
@@ -55,7 +80,7 @@ func SetRawFactory(c context.Context, tqf RawFactory) context.Context {
// with a quick mock. This is just a shorthand SetRawFactory invocation to SetRaw
// a RawFactory which always returns the same object.
func SetRaw(c context.Context, tq RawInterface) context.Context {
- return SetRawFactory(c, func(context.Context) RawInterface { return tq })
+ return SetRawFactory(c, func(context.Context, bool) RawInterface { return tq })
}
func getCurFilters(c context.Context) []RawFilter {
« no previous file with comments | « service/datastore/datastore_test.go ('k') | service/taskqueue/taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698