init
This commit is contained in:
33
internal/executor/service.go
Normal file
33
internal/executor/service.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package executor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"scheduler-backend/internal/jobdef"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
registry *jobdef.Registry
|
||||
runtime jobdef.Runtime
|
||||
}
|
||||
|
||||
func NewService(registry *jobdef.Registry, runtime jobdef.Runtime) *Service {
|
||||
return &Service{
|
||||
registry: registry,
|
||||
runtime: runtime,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Execute(ctx context.Context, handlerKey string, req jobdef.ExecuteRequest) error {
|
||||
handler, ok := s.registry.Get(handlerKey)
|
||||
if !ok {
|
||||
return fmt.Errorf("handler %s not found", handlerKey)
|
||||
}
|
||||
|
||||
if req.LogCollector == nil {
|
||||
req.LogCollector = jobdef.NewLogCollector()
|
||||
}
|
||||
|
||||
return handler.Run(ctx, s.runtime, req)
|
||||
}
|
||||
Reference in New Issue
Block a user