| OLD | NEW | 
|---|
| 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" | 
| 19 ) | 20 ) | 
| 20 | 21 | 
| 21 var ( | 22 var ( | 
| 22         currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac
     e") | 23         currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac
     e") | 
| 23         defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac
     e") | 24         defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac
     e") | 
| 24 ) | 25 ) | 
| 25 | 26 | 
| 26 //////////////////////////////// taskQueueData ///////////////////////////////// | 27 //////////////////////////////// taskQueueData ///////////////////////////////// | 
| 27 | 28 | 
| 28 type taskQueueData struct { | 29 type taskQueueData struct { | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 120         queueName, err := t.getQueueNameLocked(queueName) | 121         queueName, err := t.getQueueNameLocked(queueName) | 
| 121         if err != nil { | 122         if err != nil { | 
| 122                 return err | 123                 return err | 
| 123         } | 124         } | 
| 124 | 125 | 
| 125         t.named[queueName] = map[string]*tq.Task{} | 126         t.named[queueName] = map[string]*tq.Task{} | 
| 126         t.archived[queueName] = map[string]*tq.Task{} | 127         t.archived[queueName] = map[string]*tq.Task{} | 
| 127         return nil | 128         return nil | 
| 128 } | 129 } | 
| 129 | 130 | 
| 130 var tqOkMethods = stringSet{ | 131 var tqOkMethods = stringset.NewFromSlice("GET", "POST", "HEAD", "PUT", "DELETE") | 
| 131 »       "GET":    {}, |  | 
| 132 »       "POST":   {}, |  | 
| 133 »       "HEAD":   {}, |  | 
| 134 »       "PUT":    {}, |  | 
| 135 »       "DELETE": {}, |  | 
| 136 } |  | 
| 137 | 132 | 
| 138 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu
     eueName string) (*tq.Task, error) { | 133 func (t *taskQueueData) prepTask(c context.Context, ns string, task *tq.Task, qu
     eueName string) (*tq.Task, error) { | 
| 139         toSched := task.Duplicate() | 134         toSched := task.Duplicate() | 
| 140 | 135 | 
| 141         if toSched.Path == "" { | 136         if toSched.Path == "" { | 
| 142                 toSched.Path = "/_ah/queue/" + queueName | 137                 toSched.Path = "/_ah/queue/" + queueName | 
| 143         } | 138         } | 
| 144 | 139 | 
| 145         if toSched.ETA.IsZero() { | 140         if toSched.ETA.IsZero() { | 
| 146                 toSched.ETA = clock.Now(c).Add(toSched.Delay) | 141                 toSched.ETA = clock.Now(c).Add(toSched.Delay) | 
| 147         } else if toSched.Delay != 0 { | 142         } else if toSched.Delay != 0 { | 
| 148                 panic("taskqueue: both Delay and ETA are set") | 143                 panic("taskqueue: both Delay and ETA are set") | 
| 149         } | 144         } | 
| 150         toSched.Delay = 0 | 145         toSched.Delay = 0 | 
| 151 | 146 | 
| 152         if toSched.Method == "" { | 147         if toSched.Method == "" { | 
| 153                 toSched.Method = "POST" | 148                 toSched.Method = "POST" | 
| 154         } | 149         } | 
| 155 »       if !tqOkMethods.has(toSched.Method) { | 150 »       if !tqOkMethods.Has(toSched.Method) { | 
| 156                 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho
     d) | 151                 return nil, fmt.Errorf("taskqueue: bad method %q", toSched.Metho
     d) | 
| 157         } | 152         } | 
| 158         if toSched.Method != "POST" && toSched.Method != "PUT" { | 153         if toSched.Method != "POST" && toSched.Method != "PUT" { | 
| 159                 toSched.Payload = nil | 154                 toSched.Payload = nil | 
| 160         } | 155         } | 
| 161 | 156 | 
| 162         if _, ok := toSched.Header[currentNamespace]; !ok { | 157         if _, ok := toSched.Header[currentNamespace]; !ok { | 
| 163                 if ns != "" { | 158                 if ns != "" { | 
| 164                         if toSched.Header == nil { | 159                         if toSched.Header == nil { | 
| 165                                 toSched.Header = http.Header{} | 160                                 toSched.Header = http.Header{} | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252         return t.parent.GetTombstonedTasks() | 247         return t.parent.GetTombstonedTasks() | 
| 253 } | 248 } | 
| 254 | 249 | 
| 255 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { | 250 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { | 
| 256         return t.parent.GetScheduledTasks() | 251         return t.parent.GetScheduledTasks() | 
| 257 } | 252 } | 
| 258 | 253 | 
| 259 func (t *txnTaskQueueData) CreateQueue(queueName string) { | 254 func (t *txnTaskQueueData) CreateQueue(queueName string) { | 
| 260         t.parent.CreateQueue(queueName) | 255         t.parent.CreateQueue(queueName) | 
| 261 } | 256 } | 
| OLD | NEW | 
|---|