OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
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 | |
7 // without necessarially needing an SDK implementation present. | |
8 // | |
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 | |
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. | |
13 | |
14 package gae | |
15 | |
16 import ( | |
17 "net/http" | |
18 "time" | |
19 ) | |
20 | |
21 // DSByteString is a short byte slice (up to 1500 bytes) that can be indexed. | |
22 type DSByteString []byte | |
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 | |
83 OldestETA time.Time // zero if there are no pending tasks | |
84 | |
85 Executed1Minute int // tasks executed in the last minute | |
86 InFlight int // tasks executing now | |
87 EnforcedRate float64 // requests per second | |
88 } | |
89 | |
90 // TQRetryOptions let you control whether to retry a task and the backoff interv
als between tries. | |
91 type TQRetryOptions struct { | |
92 // 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. | |
94 RetryLimit int32 | |
95 | |
96 // 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. | |
98 AgeLimit time.Duration | |
99 | |
100 // Minimum time between successive tries (only for push tasks). | |
101 MinBackoff time.Duration | |
102 | |
103 // Maximum time between successive tries (only for push tasks). | |
104 MaxBackoff time.Duration | |
105 | |
106 // Maximum number of times to double the interval between successive tri
es before the intervals increase linearly (only for push tasks). | |
107 MaxDoublings int32 | |
108 | |
109 // 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. | |
111 ApplyZeroMaxDoublings bool | |
112 } | |
113 | |
114 // TQTask represents a taskqueue task to be executed. | |
115 type TQTask struct { | |
116 // Path is the worker URL for the task. | |
117 // If unset, it will default to /_ah/queue/<queue_name>. | |
118 Path string | |
119 | |
120 // Payload is the data for the task. | |
121 // This will be delivered as the HTTP request body. | |
122 // 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. | |
124 Payload []byte | |
125 | |
126 // Additional HTTP headers to pass at the task's execution time. | |
127 // To schedule the task to be run with an alternate app version | |
128 // or backend, set the "Host" header. | |
129 Header http.Header | |
130 | |
131 // Method is the HTTP method for the task ("GET", "POST", etc.), | |
132 // or "PULL" if this is task is destined for a pull-based queue. | |
133 // If empty, this defaults to "POST". | |
134 Method string | |
135 | |
136 // A name for the task. | |
137 // If empty, a name will be chosen. | |
138 Name string | |
139 | |
140 // Delay specifies the duration the task queue service must wait | |
141 // before executing the task. | |
142 // Either Delay or ETA may be set, but not both. | |
143 Delay time.Duration | |
144 | |
145 // ETA specifies the earliest time a task may be executed (push queues) | |
146 // or leased (pull queues). | |
147 // Either Delay or ETA may be set, but not both. | |
148 ETA time.Time | |
149 | |
150 // The number of times the task has been dispatched or leased. | |
151 RetryCount int32 | |
152 | |
153 // Tag for the task. Only used when Method is PULL. | |
154 Tag string | |
155 | |
156 // Retry options for this task. May be nil. | |
157 RetryOptions *TQRetryOptions | |
158 } | |
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 |