Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Delete() on Conn{} #21

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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