fix(task): filter tasks by after param
parent
c1ad0f03de
commit
91b0741698
|
@ -15,6 +15,7 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -302,7 +303,17 @@ func (s *Store) ListTasks(ctx context.Context, params backend.TaskSearchParams)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Seek(encodedAfter)
|
||||
|
||||
// If the taskID returned by c.Seek is greater than after param, append taskID to taskIDs.
|
||||
k, _ := c.Seek(encodedAfter)
|
||||
if bytes.Compare(k, encodedAfter) > 0 {
|
||||
var nID platform.ID
|
||||
if err := nID.Decode(k); err != nil {
|
||||
return err
|
||||
}
|
||||
taskIDs = append(taskIDs, nID)
|
||||
}
|
||||
|
||||
for k, _ := c.Next(); k != nil && len(taskIDs) < lim; k, _ = c.Next() {
|
||||
var nID platform.ID
|
||||
if err := nID.Decode(k); err != nil {
|
||||
|
|
|
@ -358,6 +358,30 @@ from(bucket:"test") |> range(start:-1h)`
|
|||
t.Fatalf("exp meta %v, got meta %v", *meta, ts[0].Meta)
|
||||
}
|
||||
|
||||
// Test ListTasks with After
|
||||
ts, err = s.ListTasks(context.Background(), backend.TaskSearchParams{After: id - 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ts) != 2 {
|
||||
t.Fatalf("expected 2 result, got %d", len(ts))
|
||||
}
|
||||
if ts[0].Task.ID != id {
|
||||
t.Fatalf("got task ID %v, exp %v", ts[0].Task.ID, id)
|
||||
}
|
||||
|
||||
if ts[1].Task.ID != newID {
|
||||
t.Fatalf("got task ID %v, exp %v", ts[1].Task.ID, newID)
|
||||
}
|
||||
|
||||
ts, err = s.ListTasks(context.Background(), backend.TaskSearchParams{After: newID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ts) != 0 {
|
||||
t.Fatalf("expected 0 result, got %d", len(ts))
|
||||
}
|
||||
|
||||
// should return the last 2 tasks
|
||||
_, err = s.CreateTask(context.Background(), backend.CreateTaskRequest{Org: orgID, AuthorizationID: authzID, Script: fmt.Sprintf(scriptFmt, 3)})
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue