39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Package taskscheduler owns tasks fetched through Gitea's RunnerService and
|
|
// dispatches them to an executor only after their identity is known.
|
|
package taskscheduler
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
|
|
|
"git.ddupan.top/panxiao81/gitea-dynamic-runner/internal/taskassignment"
|
|
)
|
|
|
|
type Assignment = taskassignment.Assignment
|
|
|
|
// Dispatcher creates exactly one executor for an already assigned Gitea task.
|
|
// It must not register another runner or ask Gitea for a task.
|
|
type Dispatcher interface {
|
|
Dispatch(context.Context, Assignment) error
|
|
}
|
|
|
|
// Scheduler implements the TaskRunner boundary used by Gitea Runner's poller.
|
|
type Scheduler struct {
|
|
TrustDomain string
|
|
Dispatcher Dispatcher
|
|
}
|
|
|
|
// Run derives identity from the fetched task before provisioning its executor.
|
|
func (s *Scheduler) Run(ctx context.Context, task *runnerv1.Task) error {
|
|
if s.Dispatcher == nil {
|
|
return errors.New("executor dispatcher is required")
|
|
}
|
|
assignment, err := taskassignment.New(task, s.TrustDomain)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return s.Dispatcher.Dispatch(ctx, assignment)
|
|
}
|