mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit with typed errors support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
88
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
Normal file
88
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Group interface {
|
||||
SessionIterator() Iterator
|
||||
}
|
||||
type Iterator interface {
|
||||
NextSession() string
|
||||
}
|
||||
|
||||
func NewGroup(ids ...string) Group {
|
||||
return &group{ids: ids}
|
||||
}
|
||||
|
||||
type group struct {
|
||||
ids []string
|
||||
}
|
||||
|
||||
func (g *group) SessionIterator() Iterator {
|
||||
return &group{ids: g.ids}
|
||||
}
|
||||
|
||||
func (g *group) NextSession() string {
|
||||
if len(g.ids) == 0 {
|
||||
return ""
|
||||
}
|
||||
v := g.ids[0]
|
||||
g.ids = g.ids[1:]
|
||||
return v
|
||||
}
|
||||
|
||||
func AllSessionIDs(g Group) (out []string) {
|
||||
if g == nil {
|
||||
return nil
|
||||
}
|
||||
it := g.SessionIterator()
|
||||
if it == nil {
|
||||
return nil
|
||||
}
|
||||
for {
|
||||
v := it.NextSession()
|
||||
if v == "" {
|
||||
return
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *Manager) Any(ctx context.Context, g Group, f func(context.Context, string, Caller) error) error {
|
||||
if g == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
iter := g.SessionIterator()
|
||||
if iter == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var lastErr error
|
||||
for {
|
||||
id := iter.NextSession()
|
||||
if id == "" {
|
||||
if lastErr != nil {
|
||||
return lastErr
|
||||
}
|
||||
return errors.Errorf("no active sessions")
|
||||
}
|
||||
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
c, err := sm.Get(timeoutCtx, id, false)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
if err := f(ctx, id, c); err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user