generated from alecodes/base-template
feat: expand readeck example
This commit is contained in:
parent
28fa3ed3cc
commit
18c277fa7d
3 changed files with 168 additions and 16 deletions
|
|
@ -199,6 +199,49 @@ func (collection *Collection) FetchNodes(
|
|||
return nil
|
||||
}
|
||||
|
||||
func PushNodes[T any](
|
||||
ctx context.Context,
|
||||
collection *Collection,
|
||||
fetcher Work[T, string],
|
||||
poolConfig *WorkConfig,
|
||||
) error {
|
||||
fmt.Printf("Pushing nodes for Collection: %d - %v\n", collection.Id, collection.name)
|
||||
|
||||
tasks := make(chan T)
|
||||
|
||||
values, errors, doneChannel := asyncTaskRunner[T, string](
|
||||
ctx,
|
||||
tasks,
|
||||
poolConfig,
|
||||
fetcher,
|
||||
)
|
||||
|
||||
for _, node := range collection.childs {
|
||||
var child T
|
||||
json.Unmarshal(node.GetMetadata(), &child)
|
||||
tasks <- child
|
||||
}
|
||||
|
||||
close(tasks)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-values:
|
||||
// TODO: add external id to node, so we can update it later
|
||||
continue
|
||||
case error, ok := <-errors:
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
return error
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-doneChannel:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Reconcilation[T any] func(src *T) (*Node, error)
|
||||
|
||||
func ReconciliateCollections[T any](src, dst *Collection, work Reconcilation[T]) error {
|
||||
|
|
|
|||
Reference in a new issue