Skip to content

Commit

Permalink
Made Exec func test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffo committed Jul 9, 2024
1 parent 57a865f commit b78626a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ type Return[JC any] struct {
Error error
}

func (p *Processor[AC, OC, JC]) init() {
func (p *Processor[AC, OC, JC]) init() error {
if p.initted {
return
return nil
}

// validate the states
for _, s := range p.states {
if !s.Terminal && s.Exec == nil {
return fmt.Errorf("State %s is non-terminal but has no Exec function", s.TriggerState)
}
}

if p.serializer == nil {
p.serializer = &NilSerializer[OC, JC]{}
}
Expand Down Expand Up @@ -124,11 +132,15 @@ func (p *Processor[AC, OC, JC]) init() {

// When a job changes state, we send it to this channel to centrally manage and re-queue
p.returnChan = make(chan Return[JC], totalConcurrency*2) // make it the size of the total amount of in flight jobs we could have so that each worker can return a task
return nil
}

// Exec this big work function, this does all the crunching
func (p *Processor[AC, OC, JC]) Exec(ctx context.Context, r *Run[OC, JC]) error {
p.init()
err := p.init()
if err != nil {
return err
}

if p.allJobsAreTerminal(r) {
slog.Info("AllJobsTerminal")
Expand Down
2 changes: 1 addition & 1 deletion processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,5 @@ func TestProcessor_NonTerminal_NoExitFunction(t *testing.T) {
p := NewProcessor[MyAppContext, MyOverallContext, MyJobContext](MyAppContext{}, states, nil, nil)
r := NewRun[MyOverallContext, MyJobContext]("name", MyOverallContext{})
err := p.Exec(context.Background(), r)
require.Errorf(t, err, "State %s is non-terminal but has no Exec function", TRIGGER_STATE_NEW)
require.ErrorContains(t, err, fmt.Sprintf("State %s is non-terminal but has no Exec function", TRIGGER_STATE_NEW))
}

0 comments on commit b78626a

Please sign in to comment.