refactor for separation of concern for better readabiliy and maintainability

This commit is contained in:
Robin Olsen
2026-03-03 11:41:07 +01:00
parent e8d9f9d1b6
commit 763f079063
11 changed files with 530 additions and 471 deletions

45
pkg/task/validation.go Normal file
View File

@@ -0,0 +1,45 @@
package task
import (
"context"
"time"
)
type ValidationEngine struct {
task Tasker
}
func (v *ValidationEngine) Start(ctx context.Context, onFeedback func(ValidationFeedback)) (done <-chan struct{}, stop chan<- struct{}) {
doneChan := make(chan struct{}, 1)
stopChan := make(chan struct{}, 1)
go func() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
feedback := v.task.Validate(ctx)
if onFeedback != nil {
onFeedback(feedback)
}
if feedback.Success {
time.Sleep(3 * time.Second)
doneChan <- struct{}{}
return
}
case <-stopChan:
return
case <-ctx.Done():
return
}
}
}()
return doneChan, stopChan
}