Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvigee committed Mar 17, 2024
1 parent 2bad83a commit 7ad3f61
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions worker2/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Dep interface {
Exec(ctx context.Context, ins InStore, outs OutStore) error
Freeze()
Frozen() bool
DirectDeps() []Dep
GetDeps() []Dep
GetHooks() []Hook

setExecution(*Execution)
Expand Down Expand Up @@ -80,7 +80,7 @@ func (a *Action) Exec(ctx context.Context, ins InStore, outs OutStore) error {
return a.Do(ctx, ins, outs)
}

func (a *Action) DirectDeps() []Dep {
func (a *Action) GetDeps() []Dep {
return a.Deps
}

Expand All @@ -107,7 +107,7 @@ func (g *Group) GetID() string {
return g.ID
}

func (g *Group) DirectDeps() []Dep {
func (g *Group) GetDeps() []Dep {
return g.Deps
}

Expand Down
4 changes: 2 additions & 2 deletions worker2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (e *Engine) deepDeps(a Dep, m map[Dep]struct{}, deps *[]Dep) {
m = map[Dep]struct{}{}
}

for _, dep := range a.DirectDeps() {
for _, dep := range a.GetDeps() {
dep := flattenNamed(dep)

if _, ok := m[dep]; ok {
Expand Down Expand Up @@ -150,7 +150,7 @@ func (e *Engine) waitForDepsAndSchedule(exec *Execution) {

exec.m.Lock()
ins := map[string]Value{}
for _, dep := range exec.Dep.DirectDeps() {
for _, dep := range exec.Dep.GetDeps() {
if dep, ok := dep.(Named); ok {
exec := e.executionForDep(dep.Dep)

Expand Down
14 changes: 7 additions & 7 deletions worker2/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestExecHook(t *testing.T) {
},
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running 1")
os.Set(MemoryValue[int]{V: 1})
os.Set(NewValue(1))
return nil
},
}
Expand Down Expand Up @@ -216,15 +216,15 @@ func TestExecDeps(t *testing.T) {
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running 1")

os.Set(MemoryValue[int]{V: 1})
os.Set(NewValue(1))
return nil
},
}
a1_2 := &Action{
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running 2")

os.Set(MemoryValue[string]{V: "hello, world"})
os.Set(NewValue("hello, world"))
return nil
},
}
Expand Down Expand Up @@ -264,15 +264,15 @@ func TestExecGroup(t *testing.T) {
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running 1")

os.Set(MemoryValue[int]{V: 1})
os.Set(NewValue(1))
return nil
},
}
a1_2 := &Action{
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running 2")

os.Set(MemoryValue[string]{V: "hello, world"})
os.Set(NewValue("hello, world"))
return nil
},
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestExecStress(t *testing.T) {
i := i
a := &Action{
Do: func(ctx context.Context, ds InStore, os OutStore) error {
os.Set(MemoryValue[int]{V: i})
os.Set(NewValue(i))
return nil
},
}
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestExecProducerConsumer(t *testing.T) {
a := &Action{
Do: func(ctx context.Context, ds InStore, os OutStore) error {
fmt.Println("Running inner", i)
os.Set(MemoryValue[int]{V: i})
os.Set(NewValue(i))
return nil
},
}
Expand Down
4 changes: 4 additions & 0 deletions worker2/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (e *Execution) Start(ctx context.Context) error {
}

func (e *Execution) run(ctx context.Context) error {
if g, ok := e.Dep.(*Group); ok {
return g.Exec(ctx, nil, e.outStore)
}

ins := &inStore{m: map[string]any{}}
for k, value := range e.inputs {
vv, err := value.Get()
Expand Down
8 changes: 6 additions & 2 deletions worker2/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ type Value interface {
Get() (any, error)
}

type MemoryValue[T any] struct {
func NewValue[T any](v T) MemValue[T] {
return MemValue[T]{V: v}
}

type MemValue[T any] struct {
V T
}

func (v MemoryValue[T]) Get() (any, error) {
func (v MemValue[T]) Get() (any, error) {
return v.V, nil
}

Expand Down

0 comments on commit 7ad3f61

Please sign in to comment.