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

Side by Side Diff: service/taskqueue/types.go

Issue 1890983004: service/taskqueue: Add NewPOSTTask, remove NewTask (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Zero value. Created 4 years, 8 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 | « service/taskqueue/taskqueue.go ('k') | 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 // 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 Task.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 taskqueue 14 package taskqueue
15 15
16 import ( 16 import (
17 "net/http"
18 "time" 17 "time"
19 ) 18 )
20 19
21 // Statistics represents statistics about a single task queue. 20 // Statistics represents statistics about a single task queue.
22 type Statistics struct { 21 type Statistics struct {
23 Tasks int // may be an approximation 22 Tasks int // may be an approximation
24 OldestETA time.Time // zero if there are no pending tasks 23 OldestETA time.Time // zero if there are no pending tasks
25 24
26 Executed1Minute int // tasks executed in the last minute 25 Executed1Minute int // tasks executed in the last minute
27 InFlight int // tasks executing now 26 InFlight int // tasks executing now
28 EnforcedRate float64 // requests per second 27 EnforcedRate float64 // requests per second
29 } 28 }
30
31 // RetryOptions let you control whether to retry a task and the backoff interval s between tries.
32 type RetryOptions struct {
33 // Number of tries/leases after which the task fails permanently and is deleted.
34 // If AgeLimit is also set, both limits must be exceeded for the task to fail permanently.
35 RetryLimit int32
36
37 // Maximum time allowed since the task's first try before the task fails permanently and is deleted (only for push tasks).
38 // If RetryLimit is also set, both limits must be exceeded for the task to fail permanently.
39 AgeLimit time.Duration
40
41 // Minimum time between successive tries (only for push tasks).
42 MinBackoff time.Duration
43
44 // Maximum time between successive tries (only for push tasks).
45 MaxBackoff time.Duration
46
47 // Maximum number of times to double the interval between successive tri es before the intervals increase linearly (only for push tasks).
48 MaxDoublings int32
49
50 // If MaxDoublings is zero, set ApplyZeroMaxDoublings to true to overrid e the default non-zero value.
51 // Otherwise a zero MaxDoublings is ignored and the default is used.
52 ApplyZeroMaxDoublings bool
53 }
54
55 // Task represents a taskqueue task to be executed.
56 type Task struct {
57 // Path is the worker URL for the task.
58 // If unset, it will default to /_ah/queue/<queue_name>.
59 Path string
60
61 // Payload is the data for the task.
62 // This will be delivered as the HTTP request body.
63 // It is only used when Method is POST, PUT or PULL.
64 // url.Values' Encode method may be used to generate this for POST reque sts.
65 Payload []byte
66
67 // Additional HTTP headers to pass at the task's execution time.
68 // To schedule the task to be run with an alternate app version
69 // or backend, set the "Host" header.
70 Header http.Header
71
72 // Method is the HTTP method for the task ("GET", "POST", etc.),
73 // or "PULL" if this is task is destined for a pull-based queue.
74 // If empty, this defaults to "POST".
75 Method string
76
77 // A name for the task.
78 // If empty, a name will be chosen.
79 Name string
80
81 // Delay specifies the duration the task queue service must wait
82 // before executing the task.
83 // Either Delay or ETA may be set, but not both.
84 Delay time.Duration
85
86 // ETA specifies the earliest time a task may be executed (push queues)
87 // or leased (pull queues).
88 // Either Delay or ETA may be set, but not both.
89 ETA time.Time
90
91 // The number of times the task has been dispatched or leased.
92 RetryCount int32
93
94 // Tag for the task. Only used when Method is PULL.
95 Tag string
96
97 // Retry options for this task. May be nil.
98 RetryOptions *RetryOptions
99 }
100
101 // Duplicate returns a deep copy of this Task.
102 func (t *Task) Duplicate() *Task {
103 ret := *t
104
105 if len(t.Header) > 0 {
106 ret.Header = make(http.Header, len(t.Header))
107 for k, vs := range t.Header {
108 newVs := make([]string, len(vs))
109 copy(newVs, vs)
110 ret.Header[k] = newVs
111 }
112 }
113
114 if len(t.Payload) > 0 {
115 ret.Payload = make([]byte, len(t.Payload))
116 copy(ret.Payload, t.Payload)
117 }
118
119 if t.RetryOptions != nil {
120 ret.RetryOptions = &RetryOptions{}
121 *ret.RetryOptions = *t.RetryOptions
122 }
123
124 return &ret
125 }
OLDNEW
« no previous file with comments | « service/taskqueue/taskqueue.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698