-
Notifications
You must be signed in to change notification settings - Fork 344
/
kv_task_results_iterator.go
66 lines (56 loc) · 1.39 KB
/
kv_task_results_iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package actions
import (
"context"
"github.com/treeverse/lakefs/pkg/kv"
)
type KVTaskResultIterator struct {
it kv.PrimaryIterator
entry *TaskResult
err error
}
// NewKVTaskResultIterator returns a new iterator over actions task results of a specific run
// 'after' determines the hook run ID which we should start the scan from, used for pagination
func NewKVTaskResultIterator(ctx context.Context, store kv.Store, repositoryID, runID, after string) (*KVTaskResultIterator, error) {
prefix := TasksPath(repositoryID, runID)
if after != "" {
after = kv.FormatPath(prefix, after)
}
it, err := kv.NewPrimaryIterator(ctx, store, (&TaskResultData{}).ProtoReflect().Type(), PartitionKey, []byte(prefix), kv.IteratorOptionsAfter([]byte(after)))
if err != nil {
return nil, err
}
return &KVTaskResultIterator{
it: *it,
}, nil
}
func (i *KVTaskResultIterator) Next() bool {
if i.Err() != nil {
return false
}
if !i.it.Next() {
i.entry = nil
return false
}
entry := i.it.Entry()
if entry == nil {
i.err = ErrNilValue
return false
}
i.entry = taskResultFromProto(entry.Value.(*TaskResultData))
return true
}
func (i *KVTaskResultIterator) Value() *TaskResult {
if i.Err() != nil {
return nil
}
return i.entry
}
func (i *KVTaskResultIterator) Err() error {
if i.err == nil {
return i.it.Err()
}
return i.err
}
func (i *KVTaskResultIterator) Close() {
i.it.Close()
}