feat: expand readeck example

This commit is contained in:
Alexander Navarro 2024-12-03 16:49:30 -03:00
parent 28fa3ed3cc
commit 18c277fa7d
3 changed files with 168 additions and 16 deletions

View file

@ -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 {

View file

@ -109,6 +109,7 @@ func (conn *DB) bootstrap() error {
id INTEGER PRIMARY KEY AUTOINCREMENT,
_class text NOT NULL,
name TEXT,
external_id TEXT,
metadata jsonb DEFAULT '{}',
original_data jsonb DEFAULT '{}'
);