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

Unified Diff: impl/prod/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 | « impl/memory/taskqueue_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/prod/context.go
diff --git a/impl/prod/context.go b/impl/prod/context.go
index 11bd6c24e33189a6c1e815b975a15ee2ff2c7b56..80d24e224f5b0dbdb3f16c5f51c80da7a924f94e 100644
--- a/impl/prod/context.go
+++ b/impl/prod/context.go
@@ -7,6 +7,7 @@ package prod
import (
"net/http"
+ "github.com/luci/gae/service/info"
"golang.org/x/net/context"
"google.golang.org/appengine"
)
@@ -14,8 +15,9 @@ import (
type key int
var (
- prodContextKey key
- probeCacheKey key = 1
+ prodContextKey key
+ prodContextNoTxnKey key = 1
+ probeCacheKey key = 2
)
// AEContext retrieves the raw "google.golang.org/appengine" compatible Context.
@@ -24,6 +26,17 @@ func AEContext(c context.Context) context.Context {
return aeCtx
}
+// AEContextNoTxn retrieves the raw "google.golang.org/appengine" compatible
+// Context that's not part of a transaction.
+func AEContextNoTxn(c context.Context) context.Context {
+ aeCtx, _ := c.Value(prodContextNoTxnKey).(context.Context)
+ aeCtx, err := appengine.Namespace(aeCtx, info.Get(c).GetNamespace())
+ if err != nil {
+ panic(err)
+ }
+ return aeCtx
+}
+
// Use adds production implementations for all the gae services to the
// context.
//
@@ -40,5 +53,6 @@ func AEContext(c context.Context) context.Context {
func Use(c context.Context, r *http.Request) context.Context {
aeCtx := appengine.NewContext(r)
c = context.WithValue(c, prodContextKey, aeCtx)
+ c = context.WithValue(c, prodContextNoTxnKey, aeCtx)
return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c))))))
}
« no previous file with comments | « impl/memory/taskqueue_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698