Files
scheduler-backend/internal/executor/service.go
2026-05-28 00:16:19 +08:00

34 lines
645 B
Go

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)
}