feat: assemble Go scheduler and backend workers
This commit is contained in:
@@ -77,28 +77,16 @@ type Worker struct {
|
||||
// returns true, all recovery information exists in Kubernetes/OpenSandbox and
|
||||
// the assignment message can be acknowledged immediately.
|
||||
func (w Worker) Accept(ctx context.Context, assignment taskassignment.Assignment) (bool, error) {
|
||||
if w.Backend == nil || w.Tasks == nil || w.Bootstrap == nil {
|
||||
return false, errors.New("backend, Gitea task state, and runner bootstrap are required")
|
||||
if w.Backend == nil || w.Bootstrap == nil {
|
||||
return false, errors.New("backend and runner bootstrap are required")
|
||||
}
|
||||
if assignment.ID == "" || assignment.Task == nil {
|
||||
return false, errors.New("valid assignment is required")
|
||||
}
|
||||
terminal, err := w.Tasks.Terminal(ctx, assignment.Task.GetId())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
executor, err := w.Backend.Find(ctx, assignment.ID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if terminal {
|
||||
if executor != nil {
|
||||
if err := w.Backend.Delete(ctx, executor); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
if executor == nil {
|
||||
launch, launchErr := w.launchSpec(assignment)
|
||||
if launchErr != nil {
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestHandleRecoversExistingExecutorWithoutCreatingAnother(t *testing.T) {
|
||||
|
||||
func TestAcceptAcknowledgesAfterBackendAndIdentityAreDurable(t *testing.T) {
|
||||
backend := &fakeBackend{}
|
||||
worker := Worker{Backend: backend, Tasks: &fakeTasks{}, Bootstrap: fakeBootstrap{}}
|
||||
worker := Worker{Backend: backend, Bootstrap: fakeBootstrap{}}
|
||||
|
||||
accepted, err := worker.Accept(context.Background(), assignment())
|
||||
if err != nil || !accepted {
|
||||
@@ -92,7 +92,7 @@ func TestAcceptAcknowledgesAfterBackendAndIdentityAreDurable(t *testing.T) {
|
||||
|
||||
func TestAcceptRetriesWhileBackendIdentityTargetIsUnavailable(t *testing.T) {
|
||||
backend := &fakeBackend{executor: &Executor{Name: "pending", Phase: PhasePending}}
|
||||
worker := Worker{Backend: backend, Tasks: &fakeTasks{}, Bootstrap: fakeBootstrap{}}
|
||||
worker := Worker{Backend: backend, Bootstrap: fakeBootstrap{}}
|
||||
|
||||
accepted, err := worker.Accept(context.Background(), assignment())
|
||||
if err != nil || accepted {
|
||||
|
||||
Reference in New Issue
Block a user