-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathput.go
More file actions
42 lines (32 loc) · 1.02 KB
/
put.go
File metadata and controls
42 lines (32 loc) · 1.02 KB
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
package cli
import (
"fmt"
"time"
"github.com/kr/beanstalk"
)
type PutCommand struct {
Tube string `short:"t" long:"tube" description:"tube to be tailed." required:"true"`
Body string `short:"b" long:"body" description:"plain text data for the job." required:"true"`
Priority uint32 `short:"" long:"priority" description:"priority for the job." default:"1024"`
Delay time.Duration `short:"" long:"delay" description:"delay for the job." default:"0"`
TTR time.Duration `short:"" long:"ttr" description:"TTR for the job." default:"60"`
Command
}
func (c *PutCommand) Execute(args []string) error {
if err := c.Init(); err != nil {
return err
}
return c.Put()
}
func (c *PutCommand) Put() error {
t := beanstalk.Tube{Conn: c.conn, Name: c.Tube}
id, err := t.Put([]byte(c.Body), c.Priority, c.Delay, c.TTR)
if err != nil {
return err
}
fmt.Printf(
"Added job with id %d to %s with priority %d, delay %s, TTR %d\n",
id, c.Tube, c.Priority, c.Delay.String(), c.TTR,
)
return nil
}