-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtaskqueue.go
69 lines (60 loc) · 1.65 KB
/
taskqueue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package appwrap
import (
"context"
"net/http"
"net/url"
"time"
)
type Taskqueue interface {
Add(c context.Context, task CloudTask, queueName string) (CloudTask, error)
AddMulti(c context.Context, tasks []CloudTask, queueName string) ([]CloudTask, error)
NewAppEngineCloudTask(path string, params url.Values) AppEngineTask
NewHttpCloudTask(serviceAccount string, url string, method string, data []byte, headers http.Header) HttpTask
}
// This is so the calling code cannot create task structs directly.
// This is important for cloud tasks, where the fields of the struct have to be populated properly
// with blank values for the various pointer fields.
type CloudTask interface {
// private method guarantees that caller can't imitate the struct
isTask()
Delay() time.Duration
SetDelay(delay time.Duration)
Name() string
SetName(name string)
RetryCount() int32
SetRetryCount(count int32)
Copy() CloudTask
Header() http.Header
SetHeader(header http.Header)
Method() string
SetMethod(method string)
Payload() []byte
SetPayload(payload []byte)
}
type AppEngineTask interface {
CloudTask
Path() string
SetPath(path string)
Service() string
SetService(service string)
Version() string
SetVersion(version string)
}
type HttpTask interface {
CloudTask
Url() string
SetUrl(url string)
}
type CloudTasksLocation string
func NewAppEngineTask() AppEngineTask {
return newAppEngineCloudTask()
}
func NewHttpCloudTask(serviceAccount string) HttpTask {
return newHttpCloudTask(serviceAccount)
}
func NewTaskqueue(c context.Context, loc CloudTasksLocation) Taskqueue {
if IsDevAppServer {
return cloudTaskqueue{}
}
return newCloudTaskqueue(c, loc)
}