Skip to content

Commit

Permalink
handle unknow job id err
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie Li authored and jackielii committed Jun 25, 2019
1 parent 4d7d08f commit ee2b034
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/pkg/errors"
)

var ErrUnknowJobID = errors.New("unknow job id")

// Process is the process's base struct, use New to create a new instance
type Process struct {
server *machinery.Server
Expand Down Expand Up @@ -476,8 +478,8 @@ func (p JobQuery) GetProgress(jobID string) (progress string, err error) {
defer p.redisLock.Unlock()

s, err := redis.String(c.Do("GET", progressSubject(jobID)))
if err != redis.ErrNil {
return "", errors.New("unknow job id")
if err == redis.ErrNil {
return "", ErrUnknowJobID
}
if err != nil {
return "", err
Expand Down
9 changes: 9 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func TestNewProcess(t *testing.T) {
break
}
progress, err := j.GetProgress(jobID)
if err == ErrUnknowJobID {
continue
}
require.NoError(t, err)
if progress != prevProgress {
prevProgress = progress
Expand Down Expand Up @@ -200,6 +203,9 @@ func ExampleProcess() {
break
}
progress, err := j.GetProgress(jobID)
if err == ErrUnknowJobID {
continue
}
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -294,6 +300,9 @@ func TestChannelAPI(t *testing.T) {
break
}
progress, err := j.GetProgress(jobID)
if err == ErrUnknowJobID {
continue
}
require.NoError(t, err)
if progress != prevProgress {
prevProgress = progress
Expand Down

0 comments on commit ee2b034

Please sign in to comment.