Skip to content

Commit

Permalink
Export Delete() on Conn{} (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
prep authored Mar 26, 2022
1 parent 5953ad7 commit 3e8f9a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
16 changes: 4 additions & 12 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ func (conn *Conn) bury(ctx context.Context, job *Job, priority uint32) error {
return err
}

func (conn *Conn) delete(ctx context.Context, job *Job) error {
ctx, span := trace.StartSpan(ctx, "github.com/prep/beanstalk/Conn.delete")
// Delete the job with the specified ID.
func (conn *Conn) Delete(ctx context.Context, id uint64) error {
ctx, span := trace.StartSpan(ctx, "github.com/prep/beanstalk/Conn.Delete")
defer span.End()

_, _, err := conn.lcommand(ctx, "delete %d", job.ID)
_, _, err := conn.lcommand(ctx, "delete %d", id)
return err
}

Expand Down Expand Up @@ -271,15 +272,6 @@ func (conn *Conn) kick(ctx context.Context, job *Job) error {
return ErrNotFound
}

// If the tube is different than the last time, switch tubes.
if job.Stats.Tube != conn.lastTube {
if _, _, err := conn.command(ctx, "use %s", job.Stats.Tube); err != nil {
return err
}

conn.lastTube = job.Stats.Tube
}

_, _, err := conn.lcommand(ctx, "kick-job %d", job.ID)
return err
}
Expand Down
9 changes: 4 additions & 5 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestConn(t *testing.T) {
})

// delete a job.
t.Run("delete", func(t *testing.T) {
t.Run("Delete", func(t *testing.T) {
server.HandleFunc(func(line Line) string {
switch {
case line.At(1, "delete 3"):
Expand All @@ -205,7 +205,7 @@ func TestConn(t *testing.T) {
return ""
})

if err := conn.delete(ctx, &Job{ID: 3}); err != nil {
if err := conn.Delete(ctx, 3); err != nil {
t.Fatalf("Error deleting job: %s", err)
}

Expand All @@ -222,7 +222,7 @@ func TestConn(t *testing.T) {
return ""
})

err := conn.delete(ctx, &Job{ID: 4})
err := conn.Delete(ctx, 4)
switch {
case errors.Is(err, ErrNotFound):
case err != nil:
Expand Down Expand Up @@ -356,8 +356,7 @@ func TestConn(t *testing.T) {
})

err := conn.release(ctx, &Job{ID: 8}, 12, 20*time.Second)
switch {
case err != nil:
if err != nil {
t.Fatalf("Error releasing job: %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion job.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (job *Job) Delete(ctx context.Context) error {
return ErrJobFinished
}

err := job.conn.delete(ctx, job)
err := job.conn.Delete(ctx, job.ID)
job.conn = nil
return err
}
Expand Down

0 comments on commit 3e8f9a9

Please sign in to comment.