| 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 prod | 5 package prod |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "reflect" | 9 "reflect" |
| 10 | 10 |
| 11 tq "github.com/luci/gae/service/taskqueue" | 11 tq "github.com/luci/gae/service/taskqueue" |
| 12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 "google.golang.org/appengine" | 13 "google.golang.org/appengine" |
| 14 "google.golang.org/appengine/taskqueue" | 14 "google.golang.org/appengine/taskqueue" |
| 15 ) | 15 ) |
| 16 | 16 |
| 17 // useTQ adds a gae.TaskQueue implementation to context, accessible | 17 // useTQ adds a gae.TaskQueue implementation to context, accessible |
| 18 // by gae.GetTQ(c) | 18 // by gae.GetTQ(c) |
| 19 func useTQ(c context.Context) context.Context { | 19 func useTQ(c context.Context) context.Context { |
| 20 return tq.SetRawFactory(c, func(ci context.Context) tq.RawInterface { | 20 return tq.SetRawFactory(c, func(ci context.Context) tq.RawInterface { |
| 21 return tqImpl{ci} | 21 return tqImpl{ci} |
| 22 }) | 22 }) |
| 23 } | 23 } |
| 24 | 24 |
| 25 type tqImpl struct { | 25 type tqImpl struct { |
| 26 context.Context | 26 context.Context |
| 27 } | 27 } |
| 28 | 28 |
| 29 func init() { | 29 func init() { |
| 30 » const taskExpectedFields = 9 | 30 » const taskExpectedFields = 10 |
| 31 » // Runtime-assert that the number of fields in the Task structs is 9, to | 31 » // Runtime-assert that the number of fields in the Task structs match, t
o |
| 32 // avoid missing additional fields if they're added later. | 32 // avoid missing additional fields if they're added later. |
| 33 // all other type assertions are statically enforced by o2n() and tqF2R(
) | 33 // all other type assertions are statically enforced by o2n() and tqF2R(
) |
| 34 | 34 |
| 35 » oldType := reflect.TypeOf((*taskqueue.Task)(nil)) | 35 » oldType := reflect.TypeOf((*taskqueue.Task)(nil)).Elem() |
| 36 » newType := reflect.TypeOf((*tq.Task)(nil)) | 36 » newType := reflect.TypeOf((*tq.Task)(nil)).Elem() |
| 37 | 37 |
| 38 if oldType.NumField() != newType.NumField() || | 38 if oldType.NumField() != newType.NumField() || |
| 39 oldType.NumField() != taskExpectedFields { | 39 oldType.NumField() != taskExpectedFields { |
| 40 panic(fmt.Errorf( | 40 panic(fmt.Errorf( |
| 41 » » » "prod/taskqueue:init() field count differs: %v, %v", | 41 » » » "prod/taskqueue:init() field count differs: %d, %d, %d", |
| 42 » » » oldType, newType)) | 42 » » » oldType.NumField(), newType.NumField(), taskExpectedFiel
ds)) |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 // tqR2F (TQ real-to-fake) converts a *taskqueue.Task to a *tq.Task. | 46 // tqR2F (TQ real-to-fake) converts a *taskqueue.Task to a *tq.Task. |
| 47 func tqR2F(o *taskqueue.Task) *tq.Task { | 47 func tqR2F(o *taskqueue.Task) *tq.Task { |
| 48 if o == nil { | 48 if o == nil { |
| 49 return nil | 49 return nil |
| 50 } | 50 } |
| 51 n := tq.Task{} | 51 n := tq.Task{} |
| 52 n.Path = o.Path | 52 n.Path = o.Path |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 for _, s := range stats { | 129 for _, s := range stats { |
| 130 cb((*tq.Statistics)(&s), nil) | 130 cb((*tq.Statistics)(&s), nil) |
| 131 } | 131 } |
| 132 return nil | 132 return nil |
| 133 } | 133 } |
| 134 | 134 |
| 135 func (t tqImpl) Testable() tq.Testable { | 135 func (t tqImpl) Testable() tq.Testable { |
| 136 return nil | 136 return nil |
| 137 } | 137 } |
| OLD | NEW |