-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
144 lines (134 loc) · 2.95 KB
/
main.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
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"fmt"
"os"
"time"
"beanstalkd-cli/command"
"github.com/urfave/cli"
)
var (
Name string
Version string
)
func main() {
command := new(command.Command)
app := cli.NewApp()
app.Name = Name
app.Usage = ""
app.HelpName = Name
app.Version = Version
app.Authors = []cli.Author{
{
Name: "Edwin Hoksberg",
Email: "[email protected]",
},
}
app.UsageText = fmt.Sprintf(`A simple cli interface for managing beanstalkd queues.
Homepage: https://github.com/edwinhoksberg/beanstalkd-cli`)
app.Commands = []cli.Command{
{
Name: "monitor",
Usage: "Monitor the beanstalkd queues",
Action: command.Monitor,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "keys",
Usage: "Different keys to monitor",
},
&cli.StringSliceFlag{
Name: "tubekeys",
Usage: "Different tube keys to monitor",
},
},
},
{
Name: "flush",
Usage: "Completely remove all jobs from a tube",
Action: command.Flush,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tube",
Usage: "The name of the tube to flush",
Value: "default",
},
},
},
{
Name: "pop",
Usage: "Remove a job from a queue and display it",
Action: command.Pop,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tube",
Usage: "The name of the tube to pop an item from",
Value: "default",
},
},
},
{
Name: "put",
Usage: "Write a job to a queue",
Action: command.Put,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tube",
Usage: "The name of the tube where a new job should be inserted",
Value: "default",
},
&cli.StringFlag{
Name: "data",
Usage: "The message to write to the queue (default reads from stdin)",
Value: "-",
},
&cli.IntFlag{
Name: "priority",
Usage: "Job priority, a lower value will be scheduled before jobs with a larger priority",
Value: 1024,
},
&cli.DurationFlag{
Name: "delay",
Usage: "How many seconds to wait before putting the job in the queue, e.g. 300s or 2h15m",
Value: 0,
},
&cli.DurationFlag{
Name: "ttr",
Usage: "The number of seconds to allow a worker to run this job, e.g. 300s or 2h15m",
Value: time.Hour,
},
},
},
{
Name: "peek",
Usage: "Display a job from the queue without removing it",
Action: command.Peek,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tube",
Usage: "The name of the tube to peek from",
Value: "default",
},
},
},
}
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Usage: "set this to enable debug logging",
},
&cli.BoolFlag{
Name: "quiet",
Usage: "set this to disable logging",
},
&cli.StringFlag{
Name: "server",
Usage: "The server name where beanstalkd is running",
Value: "127.0.0.1",
},
&cli.IntFlag{
Name: "port",
Usage: "The port on which beanstalkd is listening",
Value: 11300,
},
}
app.Run(os.Args)
}