Skip to content

Commit

Permalink
support reserve-job command (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuYin authored Dec 10, 2022
1 parent 3bed00b commit 52e4a01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ func (c *Conn) Peek(id uint64) (body []byte, err error) {
return c.readResp(r, true, "FOUND %d", &id)
}

// ReserveJob reserves the specified job by id from the server.
func (c *Conn) ReserveJob(id uint64) (body []byte, err error) {
r, err := c.cmd(nil, nil, nil, "reserve-job", id)
if err != nil {
return nil, err
}
return c.readResp(r, true, "RESERVED %d", &id)
}

// Stats retrieves global statistics from the server.
func (c *Conn) Stats() (map[string]string, error) {
r, err := c.cmd(nil, nil, nil, "stats")
Expand Down
15 changes: 15 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ func TestPeekTwice(t *testing.T) {
}
}

func TestReserveJob(t *testing.T) {
c := NewConn(mock("reserve-job 1\r\n", "RESERVED 1 1\r\nx\r\n"))

body, err := c.ReserveJob(1)
if err != nil {
t.Fatal(err)
}
if len(body) != 1 || body[0] != 'x' {
t.Fatalf("bad body, expected %#v, got %#v", "x", string(body))
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}

func TestRelease(t *testing.T) {
c := NewConn(mock("release 1 3 2\r\n", "RELEASED\r\n"))

Expand Down

0 comments on commit 52e4a01

Please sign in to comment.