建立 Go Task Scheduler 协议骨架
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// 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/taskidentity"
|
||||
)
|
||||
|
||||
// Assignment is the immutable input handed to a Pod or VM provisioner.
|
||||
type Assignment struct {
|
||||
Task *runnerv1.Task
|
||||
Identity taskidentity.Identity
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
identity, err := taskidentity.FromTask(task, s.TrustDomain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.Dispatcher.Dispatch(ctx, Assignment{Task: task, Identity: identity})
|
||||
}
|
||||
Reference in New Issue
Block a user