Skip to content

Commit

Permalink
Dedicated ctx from errgroup.WithContext
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <[email protected]>
  • Loading branch information
mrizzi committed Nov 8, 2023
1 parent c34e4f4 commit 12ef6a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions pkg/assembler/backends/ent/backend/hasMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

func (b *EntBackend) HasMetadata(ctx context.Context, filter *model.HasMetadataSpec) ([]*model.HasMetadata, error) {
fmt.Printf("HasMetadata ctx %v %+v\n", &ctx, ctx)
records, err := b.client.HasMetadata.Query().
Where(hasMetadataPredicate(filter)).
Limit(MaxPageSize).
Expand Down Expand Up @@ -60,8 +61,9 @@ func (b *EntBackend) IngestHasMetadata(ctx context.Context, subject model.Packag
}

func (b *EntBackend) IngestBulkHasMetadata(ctx context.Context, subjects model.PackageSourceOrArtifactInputs, pkgMatchType *model.MatchFlags, hasMetadataList []*model.HasMetadataInputSpec) ([]string, error) {
fmt.Printf("IngestBulkHasMetadata ctx %v %+v\n", &ctx, ctx)
var results = make([]string, len(hasMetadataList))
eg, ctx := errgroup.WithContext(ctx)
eg, egCtx := errgroup.WithContext(ctx)
for i := range hasMetadataList {
index := i
hmSpec := *hasMetadataList[index]
Expand All @@ -74,11 +76,12 @@ func (b *EntBackend) IngestBulkHasMetadata(ctx context.Context, subjects model.P
subject = model.PackageSourceOrArtifactInput{Source: subjects.Sources[index]}
}
concurrently(eg, func() error {
hm, err := b.IngestHasMetadata(ctx, subject, pkgMatchType, hmSpec)
hm, err := b.IngestHasMetadata(egCtx, subject, pkgMatchType, hmSpec)
if err == nil {
results[index] = hm.ID
return err
} else {
fmt.Printf("error is %s\n", err)
return gqlerror.Errorf("IngestBulkHasMetadata failed with element #%v %+v with err: %v", index, *subject.Package, err)
}
})
Expand Down
4 changes: 3 additions & 1 deletion pkg/assembler/backends/ent/backend/hasMetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package backend

import (
"fmt"
"strconv"
"time"

Expand Down Expand Up @@ -977,13 +978,14 @@ func (s *Suite) TestIngestBulkHasMetadata() {
}
}
for _, o := range test.Calls {
_, err := b.IngestBulkHasMetadata(ctx, o.Sub, o.Match, o.HM)
bhm, err := b.IngestBulkHasMetadata(ctx, o.Sub, o.Match, o.HM)
if (err != nil) != test.ExpIngestErr {
t.Fatalf("did not get expected ingest error, want: %v, got: %v", test.ExpIngestErr, err)
}
if err != nil {
return
}
fmt.Println("bhm", bhm)
}
got, err := b.HasMetadata(ctx, test.Query)
if (err != nil) != test.ExpQueryErr {
Expand Down

0 comments on commit 12ef6a1

Please sign in to comment.