Skip to content

Commit c65c67a

Browse files
committed
Bury: correct implementantion
1 parent 4add073 commit c65c67a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

cli/bury.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (c *BuryCommand) Execute(args []string) error {
2727
}
2828

2929
func (c *BuryCommand) Bury() error {
30-
if err := c.calcNumIfNeeded(); err != nil {
30+
if err := c.calcNum(); err != nil {
3131
return err
3232
}
3333

@@ -36,12 +36,12 @@ func (c *BuryCommand) Bury() error {
3636
return nil
3737
}
3838

39-
fmt.Printf("Trying to bury %d jobs from %q...\n", c.Num, c.Tube)
39+
fmt.Printf("Trying to bury %d jobs from %q ...\n", c.Num, c.Tube)
4040

4141
count := 0
4242
ts := beanstalk.NewTubeSet(c.conn, c.Tube)
4343
for count < c.Num {
44-
id, _, err := ts.Reserve(time.Hour * 24)
44+
id, _, err := ts.Reserve(time.Second)
4545
if err != nil {
4646
return err
4747
}
@@ -59,22 +59,23 @@ func (c *BuryCommand) Bury() error {
5959
if err := c.conn.Bury(id, uint32(pri)); err != nil {
6060
return err
6161
}
62-
fmt.Println(pri)
62+
6363
count++
6464
}
6565

6666
fmt.Printf("Actually buried %d.\n", count)
6767
return nil
6868
}
6969

70-
func (c *BuryCommand) calcNumIfNeeded() error {
71-
if c.Num == 0 {
72-
s, err := c.GetStatsForTube(c.Tube)
73-
if err != nil {
74-
return err
75-
}
70+
func (c *BuryCommand) calcNum() error {
71+
s, err := c.GetStatsForTube(c.Tube)
72+
if err != nil {
73+
return err
74+
}
7675

76+
if c.Num == 0 || c.Num > s.JobsReady {
7777
c.Num = s.JobsReady
78+
return nil
7879
}
7980

8081
return nil

cli/kick.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *KickCommand) Kick() error {
3434
return nil
3535
}
3636

37-
fmt.Printf("Trying to kick %d jobs from %q...\n", c.Num, c.Tube)
37+
fmt.Printf("Trying to kick %d jobs from %q ...\n", c.Num, c.Tube)
3838

3939
t := &beanstalk.Tube{c.conn, c.Tube}
4040
kicked, err := t.Kick(c.Num)

0 commit comments

Comments
 (0)