Skip to content

Commit

Permalink
Fix bug in no-job response
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 3, 2020
1 parent 47449d8 commit a828c19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ func TestPostJob(t *testing.T) {
}

func TestGetJobStatus(t *testing.T) {
_, err := cl.GetJobStatus("aaaa")
assert.Error(t, err)
for _, j := range jobs {
r, err := cl.GetJobStatus(j.JobID)
assert.NoError(t, err, "error posting job")
assert.NoError(t, err, "error getting job status")
assert.Equal(t, j.JobID, r.JobID)
}
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-chi/chi v3.3.3+incompatible
github.com/go-sql-driver/mysql v1.4.0
github.com/golang/protobuf v1.3.1 // indirect
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/uuid v1.1.1 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
Expand Down
9 changes: 7 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/RichardKnop/machinery/v1/tasks"
"github.com/go-chi/chi"
"github.com/gomodule/redigo/redis"
"github.com/knadh/sql-jobber/models"
)

Expand All @@ -31,8 +32,12 @@ func handleGetTasksList(w http.ResponseWriter, r *http.Request) {

// handleGetJobStatus returns the status of a given jobID.
func handleGetJobStatus(w http.ResponseWriter, r *http.Request) {
out, err := jobber.Machinery.GetBackend().GetState(chi.URLParam(r, "jobID"))
if err != nil {
jobID := chi.URLParam(r, "jobID")
out, err := jobber.Machinery.GetBackend().GetState(jobID)
if err == redis.ErrNil {
sendErrorResponse(w, "job not found", http.StatusNotFound)
return
} else if err != nil {
sysLog.Printf("error fetching job status: %v", err)
sendErrorResponse(w, "error fetching job status", http.StatusInternalServerError)
return
Expand Down

0 comments on commit a828c19

Please sign in to comment.