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 // This file contains types which are mirrors/duplicates of the upstream SDK | 5 // This file contains types which are mirrors/duplicates of the upstream SDK |
6 // types. This exists so that users can depend solely on this wrapper library | 6 // types. This exists so that users can depend solely on this wrapper library |
7 // without necessarially needing an SDK implementation present. | 7 // without necessarially needing an SDK implementation present. |
8 // | 8 // |
9 // This was done (instead of type-aliasing from the github version of the SDK) | 9 // This was done (instead of type-aliasing from the github version of the SDK) |
10 // because some of the types need to be tweaked (like TQTask.RetryOptions) to | 10 // because some of the types need to be tweaked (like Task.RetryOptions) to |
11 // interact well with the wrapper, and the inconsistency of having some types | 11 // interact well with the wrapper, and the inconsistency of having some types |
12 // defined by the gae package and others defined by the SDK was pretty awkward. | 12 // defined by the gae package and others defined by the SDK was pretty awkward. |
13 | 13 |
14 package gae | 14 package taskqueue |
15 | 15 |
16 import ( | 16 import ( |
17 "net/http" | 17 "net/http" |
18 "time" | 18 "time" |
19 ) | 19 ) |
20 | 20 |
21 // DSByteString is a short byte slice (up to 1500 bytes) that can be indexed. | 21 // Statistics represents statistics about a single task queue. |
22 type DSByteString []byte | 22 type Statistics struct { |
23 | |
24 // BSKey is a key for a blobstore blob. | |
25 // | |
26 // Conceptually, this type belongs in the blobstore package, but it lives in the | |
27 // appengine package to avoid a circular dependency: blobstore depends on | |
28 // datastore, and datastore needs to refer to the BSKey type. | |
29 // | |
30 // Blobstore is NOT YET supported by gae, but may be supported later. Its | |
31 // inclusion here is so that the RawDatastore can interact (and round-trip) | |
32 // correctly with other datastore API implementations. | |
33 type BSKey string | |
34 | |
35 // DSGeoPoint represents a location as latitude/longitude in degrees. | |
36 // | |
37 // You probably shouldn't use these, but their inclusion here is so that the | |
38 // RawDatastore can interact (and round-trip) correctly with other datastore API | |
39 // implementations. | |
40 type DSGeoPoint struct { | |
41 » Lat, Lng float64 | |
42 } | |
43 | |
44 // Valid returns whether a DSGeoPoint is within [-90, 90] latitude and [-180, | |
45 // 180] longitude. | |
46 func (g DSGeoPoint) Valid() bool { | |
47 » return -90 <= g.Lat && g.Lat <= 90 && -180 <= g.Lng && g.Lng <= 180 | |
48 } | |
49 | |
50 // DSTransactionOptions are the options for running a transaction. | |
51 type DSTransactionOptions struct { | |
52 » // XG is whether the transaction can cross multiple entity groups. In | |
53 » // comparison, a single group transaction is one where all datastore key
s | |
54 » // used have the same root key. Note that cross group transactions do no
t | |
55 » // have the same behavior as single group transactions. In particular, i
t | |
56 » // is much more likely to see partially applied transactions in differen
t | |
57 » // entity groups, in global queries. | |
58 » // It is valid to set XG to true even if the transaction is within a | |
59 » // single entity group. | |
60 » XG bool | |
61 » // Attempts controls the number of retries to perform when commits fail | |
62 » // due to a conflicting transaction. If omitted, it defaults to 3. | |
63 » Attempts int | |
64 } | |
65 | |
66 // MCStatistics represents a set of statistics about the memcache cache. This | |
67 // may include items that have expired but have not yet been removed from the | |
68 // cache. | |
69 type MCStatistics struct { | |
70 » Hits uint64 // Counter of cache hits | |
71 » Misses uint64 // Counter of cache misses | |
72 » ByteHits uint64 // Counter of bytes transferred for gets | |
73 | |
74 » Items uint64 // Items currently in the cache | |
75 » Bytes uint64 // Size of all items currently in the cache | |
76 | |
77 » Oldest int64 // Age of access of the oldest item, in seconds | |
78 } | |
79 | |
80 // TQStatistics represents statistics about a single task queue. | |
81 type TQStatistics struct { | |
82 Tasks int // may be an approximation | 23 Tasks int // may be an approximation |
83 OldestETA time.Time // zero if there are no pending tasks | 24 OldestETA time.Time // zero if there are no pending tasks |
84 | 25 |
85 Executed1Minute int // tasks executed in the last minute | 26 Executed1Minute int // tasks executed in the last minute |
86 InFlight int // tasks executing now | 27 InFlight int // tasks executing now |
87 EnforcedRate float64 // requests per second | 28 EnforcedRate float64 // requests per second |
88 } | 29 } |
89 | 30 |
90 // TQRetryOptions let you control whether to retry a task and the backoff interv
als between tries. | 31 // RetryOptions let you control whether to retry a task and the backoff interval
s between tries. |
91 type TQRetryOptions struct { | 32 type RetryOptions struct { |
92 // Number of tries/leases after which the task fails permanently and is
deleted. | 33 // Number of tries/leases after which the task fails permanently and is
deleted. |
93 // If AgeLimit is also set, both limits must be exceeded for the task to
fail permanently. | 34 // If AgeLimit is also set, both limits must be exceeded for the task to
fail permanently. |
94 RetryLimit int32 | 35 RetryLimit int32 |
95 | 36 |
96 // Maximum time allowed since the task's first try before the task fails
permanently and is deleted (only for push tasks). | 37 // Maximum time allowed since the task's first try before the task fails
permanently and is deleted (only for push tasks). |
97 // If RetryLimit is also set, both limits must be exceeded for the task
to fail permanently. | 38 // If RetryLimit is also set, both limits must be exceeded for the task
to fail permanently. |
98 AgeLimit time.Duration | 39 AgeLimit time.Duration |
99 | 40 |
100 // Minimum time between successive tries (only for push tasks). | 41 // Minimum time between successive tries (only for push tasks). |
101 MinBackoff time.Duration | 42 MinBackoff time.Duration |
102 | 43 |
103 // Maximum time between successive tries (only for push tasks). | 44 // Maximum time between successive tries (only for push tasks). |
104 MaxBackoff time.Duration | 45 MaxBackoff time.Duration |
105 | 46 |
106 // Maximum number of times to double the interval between successive tri
es before the intervals increase linearly (only for push tasks). | 47 // Maximum number of times to double the interval between successive tri
es before the intervals increase linearly (only for push tasks). |
107 MaxDoublings int32 | 48 MaxDoublings int32 |
108 | 49 |
109 // If MaxDoublings is zero, set ApplyZeroMaxDoublings to true to overrid
e the default non-zero value. | 50 // If MaxDoublings is zero, set ApplyZeroMaxDoublings to true to overrid
e the default non-zero value. |
110 // Otherwise a zero MaxDoublings is ignored and the default is used. | 51 // Otherwise a zero MaxDoublings is ignored and the default is used. |
111 ApplyZeroMaxDoublings bool | 52 ApplyZeroMaxDoublings bool |
112 } | 53 } |
113 | 54 |
114 // TQTask represents a taskqueue task to be executed. | 55 // Task represents a taskqueue task to be executed. |
115 type TQTask struct { | 56 type Task struct { |
116 // Path is the worker URL for the task. | 57 // Path is the worker URL for the task. |
117 // If unset, it will default to /_ah/queue/<queue_name>. | 58 // If unset, it will default to /_ah/queue/<queue_name>. |
118 Path string | 59 Path string |
119 | 60 |
120 // Payload is the data for the task. | 61 // Payload is the data for the task. |
121 // This will be delivered as the HTTP request body. | 62 // This will be delivered as the HTTP request body. |
122 // It is only used when Method is POST, PUT or PULL. | 63 // It is only used when Method is POST, PUT or PULL. |
123 // url.Values' Encode method may be used to generate this for POST reque
sts. | 64 // url.Values' Encode method may be used to generate this for POST reque
sts. |
124 Payload []byte | 65 Payload []byte |
125 | 66 |
(...skipping 21 matching lines...) Expand all Loading... |
147 // Either Delay or ETA may be set, but not both. | 88 // Either Delay or ETA may be set, but not both. |
148 ETA time.Time | 89 ETA time.Time |
149 | 90 |
150 // The number of times the task has been dispatched or leased. | 91 // The number of times the task has been dispatched or leased. |
151 RetryCount int32 | 92 RetryCount int32 |
152 | 93 |
153 // Tag for the task. Only used when Method is PULL. | 94 // Tag for the task. Only used when Method is PULL. |
154 Tag string | 95 Tag string |
155 | 96 |
156 // Retry options for this task. May be nil. | 97 // Retry options for this task. May be nil. |
157 » RetryOptions *TQRetryOptions | 98 » RetryOptions *RetryOptions |
158 } | 99 } |
159 | |
160 // GICertificate represents a public certificate for the app. | |
161 type GICertificate struct { | |
162 KeyName string | |
163 Data []byte // PEM-encoded X.509 certificate | |
164 } | |
OLD | NEW |