-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_queue.go
67 lines (61 loc) · 1.56 KB
/
manage_queue.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
package commands
import (
"encoding/json"
"github.com/lefuturiste/jobatator/pkg/store"
)
// ListQueues - List all the queues in a group
func ListQueues(cmd CmdInterface) {
var queues []store.Queue
// filter all the queues inside a particular group
for _, queue := range store.Queues {
if queue.Group.Slug == cmd.User.CurrentGroup.Slug {
queues = append(queues, queue)
}
}
rawJSON, _ := json.Marshal(queues)
ReturnString(cmd, string(rawJSON))
}
// DeleteQueue - Delete a queue
func DeleteQueue(cmd CmdInterface) {
queue, err := store.FindQueueBySlug(cmd.Parts[1], cmd.User.CurrentGroup, false)
if err != nil {
ReturnError(cmd, err.Error())
return
}
err = queue.Delete()
if err != nil {
ReturnError(cmd, err.Error())
return
}
ReturnString(cmd, "OK")
}
// PurgeJobs - Will delete every jobs in a queue
func PurgeJobs(cmd CmdInterface) {
queue, err := store.FindQueueBySlug(cmd.Parts[1], cmd.User.CurrentGroup, false)
if err != nil {
ReturnError(cmd, err.Error())
return
}
queue.Jobs = make([]store.Job, 0)
err = queue.Update()
if err != nil {
ReturnError(cmd, err.Error())
return
}
ReturnString(cmd, "OK")
}
// PurgeWorkers - Will delete every worker in a queue (so unsubscribe all the worker from a particular queue)
func PurgeWorkers(cmd CmdInterface) {
queue, err := store.FindQueueBySlug(cmd.Parts[1], cmd.User.CurrentGroup, false)
if err != nil {
ReturnError(cmd, err.Error())
return
}
queue.Workers = make([]store.User, 0)
err = queue.Update()
if err != nil {
ReturnError(cmd, err.Error())
return
}
ReturnString(cmd, "OK")
}