Skip to content

Commit

Permalink
add default progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie Li committed Jul 25, 2019
1 parent 1363896 commit d509922
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,20 @@ func (p Process) CallWithHeaders(funcName string, args []tasks.Arg, headers task
return "", errors.Wrapf(err, "call func %s", funcName)
}

return r.Signature.UUID, nil
// make sure progress is always set for once
jobID = r.Signature.UUID
jq, err := p.OpenJobQuery()
if err != nil {
return jobID, err
}
defer jq.Close()

err = jq.SetProgress(jobID, "")
if err != nil {
return jobID, err
}

return jobID, nil
}

// GetResult retrives a AsyncResult using the jobID
Expand Down
32 changes: 32 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func ExampleProcess() {
if err != nil {
log.Fatal(err)
}
// first progress is empty default progres
if progress == "" {
continue
}
if progress != prevProgress {
prevProgress = progress
fmt.Println(progress)
Expand Down Expand Up @@ -483,3 +487,31 @@ func TestProgressNoWaitNonBlock(t *testing.T) {
time.Sleep(100 * time.Millisecond)
jq.Close()
}

func TestProgressAlwaysSet(t *testing.T) {
p, err := New("redis://localhost:6379")
require.NoError(t, err)
task := func(ctx context.Context, msg string) (string, error) {
time.Sleep(3 * time.Second)
return "received " + msg, nil
}

p.RegisterFunc(task)

jobID, err := p.Invoke(task,
[]tasks.Arg{
{
Type: "string",
Value: "test invoke",
},
},
)
require.NoError(t, err)

jq, err := p.OpenJobQuery()
require.NoError(t, err)

progress, err := jq.GetProgress(jobID)
require.NoError(t, err)
assert.Equal(t, progress, "")
}

0 comments on commit d509922

Please sign in to comment.