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

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

Issue 2512093002: Add support for Pull Queues to prod implementation. (Closed)
Patch Set: Created 4 years, 1 month 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 | « impl/prod/taskqueue.go ('k') | service/taskqueue/raw_interface.go » ('j') | 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 LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package taskqueue 5 package taskqueue
6 6
7 import ( 7 import (
8 "github.com/luci/luci-go/common/errors" 8 "github.com/luci/luci-go/common/errors"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 }) 49 })
50 if err == nil { 50 if err == nil {
51 err = lme.Get() 51 err = lme.Get()
52 if len(tasks) == 1 { 52 if len(tasks) == 1 {
53 err = errors.SingleError(err) 53 err = errors.SingleError(err)
54 } 54 }
55 } 55 }
56 return err 56 return err
57 } 57 }
58 58
59 // NOTE(riannucci): No support for pull taskqueues. We're not planning on 59 // NOTE(riannucci): Pull task queues API can be extended to support automatic
60 // making pull-queue clients which RUN in appengine (e.g. they'd all be 60 // lease management.
61 // external REST consumers). If someone needs this, it will need to be added 61 //
62 // here and in RawInterface. The theory is that a good lease API might look 62 // The theory is that a good lease API might look like:
63 // like:
64 // 63 //
65 // func Lease(queueName, tag string, batchSize int, duration time.Time, cb fun c(*Task, error<-)) 64 // func Lease(queueName, tag string, batchSize int, duration time.Time, cb fun c(*Task, error<-))
66 // 65 //
67 // Which blocks and calls cb for each task obtained. Lease would then do all 66 // Which blocks and calls cb for each task obtained. Lease would then do all
68 // necessary backoff negotiation with the backend. The callback could execute 67 // necessary backoff negotiation with the backend. The callback could execute
69 // synchronously (stuffing an error into the chan or panicing if it fails), or 68 // synchronously (stuffing an error into the chan or panicing if it fails), or
70 // asynchronously (dispatching a goroutine which will then populate the error 69 // asynchronously (dispatching a goroutine which will then populate the error
71 // channel if needed). If it operates asynchronously, it has the option of 70 // channel if needed). If it operates asynchronously, it has the option of
72 // processing multiple work items at a time. 71 // processing multiple work items at a time.
73 // 72 //
74 // Lease would also take care of calling ModifyLease as necessary to ensure 73 // Lease would also take care of calling ModifyLease as necessary to ensure
75 // that each call to cb would have 'duration' amount of time to work on the 74 // that each call to cb would have 'duration' amount of time to work on the
76 // task, as well as releasing as many leased tasks as it can on a failure. 75 // task, as well as releasing as many leased tasks as it can on a failure.
77 76
77 // Lease leases tasks from a queue.
Vadim Sh. 2016/11/18 03:42:12 all docs are copy-paste from official site
78 //
79 // leaseTime is in seconds. The number of tasks fetched will be at most
Vadim Sh. 2016/11/18 03:53:53 actually int for leaseTime is BS, I'll convert it
80 // maxTasks.
81 func Lease(c context.Context, maxTasks int, queueName string, leaseTime int) ([] *Task, error) {
82 return Raw(c).Lease(maxTasks, queueName, leaseTime)
83 }
84
85 // LeaseByTag leases tasks from a queue, grouped by tag.
86 //
87 // If tag is empty, then the returned tasks are grouped by the tag of the task
Vadim Sh. 2016/11/18 03:42:12 :( why they did it, I'll have to reimplement all t
88 // with earliest ETA.
89 //
90 // leaseTime is in seconds. The number of tasks fetched will be at most
91 // maxTasks.
92 func LeaseByTag(c context.Context, maxTasks int, queueName string, leaseTime int , tag string) ([]*Task, error) {
93 return Raw(c).LeaseByTag(maxTasks, queueName, leaseTime, tag)
94 }
95
96 // ModifyLease modifies the lease of a task.
97 //
98 // Used to request more processing time, or to abandon processing. leaseTime is
99 // in seconds and must not be negative.
100 func ModifyLease(c context.Context, task *Task, queueName string, leaseTime int) error {
101 return Raw(c).ModifyLease(task, queueName, leaseTime)
102 }
103
78 // Purge purges all tasks form the named queue. 104 // Purge purges all tasks form the named queue.
79 func Purge(c context.Context, queueName string) error { 105 func Purge(c context.Context, queueName string) error {
80 return Raw(c).Purge(queueName) 106 return Raw(c).Purge(queueName)
81 } 107 }
82 108
83 // Stats returns Statistics instances for each of the named task queues. 109 // Stats returns Statistics instances for each of the named task queues.
84 // 110 //
85 // If only one task is provided its error will be returned directly. If more 111 // If only one task is provided its error will be returned directly. If more
86 // than one task is provided, an errors.MultiError will be returned in the 112 // than one task is provided, an errors.MultiError will be returned in the
87 // event of an error, with a given error index corresponding to the error 113 // event of an error, with a given error index corresponding to the error
(...skipping 15 matching lines...) Expand all
103 } 129 }
104 } 130 }
105 return ret, err 131 return ret, err
106 } 132 }
107 133
108 // GetTestable returns a Testable for the current task queue service in c, or 134 // GetTestable returns a Testable for the current task queue service in c, or
109 // nil if it does not offer one. 135 // nil if it does not offer one.
110 func GetTestable(c context.Context) Testable { 136 func GetTestable(c context.Context) Testable {
111 return Raw(c).GetTestable() 137 return Raw(c).GetTestable()
112 } 138 }
OLDNEW
« no previous file with comments | « impl/prod/taskqueue.go ('k') | service/taskqueue/raw_interface.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698