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

Side by Side Diff: impl/memory/taskqueue_data.go

Issue 1550863002: impl/memory: Add "PULL" as valid taskqueue method. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Pull tasks can have data. Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "net/http" 10 "net/http"
11 "sync" 11 "sync"
12 "sync/atomic" 12 "sync/atomic"
13 13
14 "golang.org/x/net/context" 14 "golang.org/x/net/context"
15 15
16 ds "github.com/luci/gae/service/datastore" 16 ds "github.com/luci/gae/service/datastore"
17 tq "github.com/luci/gae/service/taskqueue" 17 tq "github.com/luci/gae/service/taskqueue"
18 "github.com/luci/luci-go/common/clock" 18 "github.com/luci/luci-go/common/clock"
19 "github.com/luci/luci-go/common/stringset"
20 ) 19 )
21 20
22 var ( 21 var (
23 currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac e") 22 currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac e")
24 defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac e") 23 defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac e")
25 ) 24 )
26 25
27 //////////////////////////////// taskQueueData ///////////////////////////////// 26 //////////////////////////////// taskQueueData /////////////////////////////////
28 27
29 type taskQueueData struct { 28 type taskQueueData struct {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 queueName, err := t.getQueueNameLocked(queueName) 120 queueName, err := t.getQueueNameLocked(queueName)
122 if err != nil { 121 if err != nil {
123 return err 122 return err
124 } 123 }
125 124
126 t.named[queueName] = map[string]*tq.Task{} 125 t.named[queueName] = map[string]*tq.Task{}
127 t.archived[queueName] = map[string]*tq.Task{} 126 t.archived[queueName] = map[string]*tq.Task{}
128 return nil 127 return nil
129 } 128 }
130 129
131 var tqOkMethods = stringset.NewFromSlice("GET", "POST", "HEAD", "PUT", "DELETE")
132
133 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu eueName string) (*tq.Task, error) { 130 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu eueName string) (*tq.Task, error) {
134 toSched := task.Duplicate() 131 toSched := task.Duplicate()
135 132
136 if toSched.Path == "" { 133 if toSched.Path == "" {
137 toSched.Path = "/_ah/queue/" + queueName 134 toSched.Path = "/_ah/queue/" + queueName
138 } 135 }
139 136
140 if toSched.ETA.IsZero() { 137 if toSched.ETA.IsZero() {
141 toSched.ETA = clock.Now(c).Add(toSched.Delay) 138 toSched.ETA = clock.Now(c).Add(toSched.Delay)
142 } else if toSched.Delay != 0 { 139 } else if toSched.Delay != 0 {
143 panic("taskqueue: both Delay and ETA are set") 140 panic("taskqueue: both Delay and ETA are set")
144 } 141 }
145 toSched.Delay = 0 142 toSched.Delay = 0
146 143
147 » if toSched.Method == "" { 144 » switch toSched.Method {
145 » // Methods that can have payloads.
146 » case "":
148 toSched.Method = "POST" 147 toSched.Method = "POST"
149 » } 148 » » fallthrough
150 » if !tqOkMethods.Has(toSched.Method) { 149 » case "POST", "PUT", "PULL":
150 » » break
151
152 » // Methods that can not have payloads.
153 » case "GET", "HEAD", "DELETE":
154 » » toSched.Payload = nil
155
156 » default:
151 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho d) 157 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho d)
152 } 158 }
153 if toSched.Method != "POST" && toSched.Method != "PUT" {
154 toSched.Payload = nil
155 }
156 159
157 if _, ok := toSched.Header[currentNamespace]; !ok { 160 if _, ok := toSched.Header[currentNamespace]; !ok {
158 if ns != "" { 161 if ns != "" {
159 if toSched.Header == nil { 162 if toSched.Header == nil {
160 toSched.Header = http.Header{} 163 toSched.Header = http.Header{}
161 } 164 }
162 toSched.Header[currentNamespace] = []string{ns} 165 toSched.Header[currentNamespace] = []string{ns}
163 } 166 }
164 } 167 }
165 // TODO(riannucci): implement DefaultNamespace 168 // TODO(riannucci): implement DefaultNamespace
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return t.parent.GetTombstonedTasks() 250 return t.parent.GetTombstonedTasks()
248 } 251 }
249 252
250 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { 253 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData {
251 return t.parent.GetScheduledTasks() 254 return t.parent.GetScheduledTasks()
252 } 255 }
253 256
254 func (t *txnTaskQueueData) CreateQueue(queueName string) { 257 func (t *txnTaskQueueData) CreateQueue(queueName string) {
255 t.parent.CreateQueue(queueName) 258 t.parent.CreateQueue(queueName)
256 } 259 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698