From 47f8e6f74cd7fb36bf2b5eb3885bbd995bcf81c0 Mon Sep 17 00:00:00 2001 From: Louis Garman <75728+leg100@users.noreply.github.com> Date: Sun, 10 Dec 2023 16:23:04 +0000 Subject: [PATCH] fix: allocator restarting unnecessarily (#666) Fixes an issue whereby everytime a job runs the allocator service would restart. --- internal/agent/allocator.go | 3 ++- internal/agent/allocator_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/agent/allocator.go b/internal/agent/allocator.go index 67e25df91..4599d4fbc 100644 --- a/internal/agent/allocator.go +++ b/internal/agent/allocator.go @@ -151,7 +151,8 @@ func (a *allocator) allocate(ctx context.Context) error { a.agents[*job.AgentID].CurrentJobs-- continue default: - return fmt.Errorf("unknown job status: %s", job.Status) + // job running; ignore + continue } // allocate job to available agent var available []*Agent diff --git a/internal/agent/allocator_test.go b/internal/agent/allocator_test.go index 91da5025b..59f3c14df 100644 --- a/internal/agent/allocator_test.go +++ b/internal/agent/allocator_test.go @@ -166,6 +166,14 @@ func TestAllocator_allocate(t *testing.T) { wantJob: nil, wantAgents: map[string]*Agent{"agent-1": {ID: "agent-1", CurrentJobs: 0}}, }, + { + name: "ignore running job", + job: &Job{ + Spec: JobSpec{RunID: "run-123", Phase: internal.PlanPhase}, + Status: JobRunning, + AgentID: internal.String("agent-1"), + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {