-
Notifications
You must be signed in to change notification settings - Fork 13
/
task_commands.go
131 lines (111 loc) · 3.1 KB
/
task_commands.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package celeriac
import ()
/*
baseCmd defines a base command for interacting with worker tasks
*/
type baseCmd struct {
Command string `json:"method"`
Destination string `json:"destination"`
}
//------------------------------------------------------------------------------
type revokeTaskArgs struct {
TaskID string `json:"task_id"`
Terminate bool `json:"terminate"`
Signal string `josn:"signal"`
}
// RevokeTaskCmd is a wrapper to a command
type RevokeTaskCmd struct {
baseCmd
Arguments revokeTaskArgs `json:"arguments"`
}
/*
NewRevokeTaskCmd creates a new command for revoking a task by given id
If a task is revoked, the workers will ignore the task and not execute it after all.
*/
func NewRevokeTaskCmd(taskID string, terminateProcess bool) *RevokeTaskCmd {
return &RevokeTaskCmd{
baseCmd: baseCmd{
Command: "revoke",
Destination: "",
},
Arguments: revokeTaskArgs{
TaskID: taskID,
Terminate: terminateProcess,
Signal: "SIGTERM",
},
}
}
//------------------------------------------------------------------------------
// PingCmd is a wrapper to a command
type PingCmd struct {
baseCmd
}
// NewPingCmd creates a new command for pinging workers
func NewPingCmd() *PingCmd {
return &PingCmd{
baseCmd: baseCmd{
Command: "ping",
Destination: "",
},
}
}
//------------------------------------------------------------------------------
// Set rate limit for task by type
type rateLimitTaskArgs struct {
TaskName string `json:"task_name"`
RateLimit string `json:"rate_limit"`
}
// RateLimitTaskCmd is a wrapper to a command
type RateLimitTaskCmd struct {
baseCmd
Arguments rateLimitTaskArgs `json:"arguments"`
}
/*
NewRateLimitTaskCmd creates a new command for rate limiting a task
taskName: Name of task to change rate limit for
rateLimit: The rate limit as tasks per second, or a rate limit string (`"100/m"`, etc.
see :attr:`celery.task.base.Task.rate_limit` for more information)
*/
func NewRateLimitTaskCmd(taskName string, rateLimit string) *RateLimitTaskCmd {
return &RateLimitTaskCmd{
baseCmd: baseCmd{
Command: "rate_limit",
Destination: "",
},
Arguments: rateLimitTaskArgs{
TaskName: taskName,
RateLimit: rateLimit,
},
}
}
//------------------------------------------------------------------------------
// Set time limit for task by type
type timeLimitTaskArgs struct {
TaskName string `json:"task_name"`
HardLimit string `json:"hard"`
SoftLimit string `json:"soft"`
}
// TimeLimitTaskCmd is a wrapper to a command
type TimeLimitTaskCmd struct {
baseCmd
Arguments timeLimitTaskArgs `json:"arguments"`
}
/*
NewTimeLimitTaskCmd creates a new command for rate limiting a task
taskName: Name of task to change rate limit for
hardLimit: New hard time limit (in seconds)
softLimit: New soft time limit (in seconds)
*/
func NewTimeLimitTaskCmd(taskName string, hardLimit string, softLimit string) *TimeLimitTaskCmd {
return &TimeLimitTaskCmd{
baseCmd: baseCmd{
Command: "time_limit",
Destination: "",
},
Arguments: timeLimitTaskArgs{
TaskName: taskName,
HardLimit: hardLimit,
SoftLimit: softLimit,
},
}
}