Modify filter for runners that should deleted

Only "dead" jobs are now not requested to be deleted. Before also pending and starting runners are ignored.
This commit is contained in:
Maximilian Paß
2021-12-22 14:11:39 +01:00
parent d57a0c07b8
commit 251129aa74
2 changed files with 9 additions and 6 deletions

View File

@ -39,7 +39,7 @@ type ExecutorAPI interface {
// LoadRunnerJobs loads all runner jobs specific for the environment.
LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi.Job, error)
// LoadRunnerIDs returns the IDs of all runners with the specified id prefix which are running and not about to
// LoadRunnerIDs returns the IDs of all runners with the specified id prefix which are not about to
// get stopped.
LoadRunnerIDs(prefix string) (runnerIds []string, err error)
@ -101,8 +101,8 @@ func (a *APIClient) LoadRunnerIDs(prefix string) (runnerIDs []string, err error)
return nil, err
}
for _, jobListStub := range list {
allocationRunning := jobListStub.JobSummary.Summary[TaskGroupName].Running > 0
if jobListStub.Status == structs.JobStatusRunning && allocationRunning {
// Filter out dead ("complete", "failed" or "lost") jobs
if jobListStub.Status != structs.JobStatusDead {
runnerIDs = append(runnerIDs, jobListStub.ID)
}
}

View File

@ -86,13 +86,14 @@ func (s *LoadRunnersTestSuite) TestAvailableRunnerIsReturned() {
s.Equal(s.availableRunner.ID, returnedIds[0])
}
func (s *LoadRunnersTestSuite) TestPendingRunnerIsNotReturned() {
func (s *LoadRunnersTestSuite) TestPendingRunnerIsReturned() {
s.mock.On("listJobs", mock.AnythingOfType("string")).
Return([]*nomadApi.JobListStub{s.pendingRunner}, nil)
returnedIds, err := s.nomadAPIClient.LoadRunnerIDs(s.jobID)
s.Require().NoError(err)
s.Empty(returnedIds)
s.Len(returnedIds, 1)
s.Equal(s.pendingRunner.ID, returnedIds[0])
}
func (s *LoadRunnersTestSuite) TestDeadRunnerIsNotReturned() {
@ -116,9 +117,11 @@ func (s *LoadRunnersTestSuite) TestReturnsAllAvailableRunners() {
returnedIds, err := s.nomadAPIClient.LoadRunnerIDs(s.jobID)
s.Require().NoError(err)
s.Len(returnedIds, 2)
s.Len(returnedIds, 3)
s.Contains(returnedIds, s.availableRunner.ID)
s.Contains(returnedIds, s.anotherAvailableRunner.ID)
s.Contains(returnedIds, s.pendingRunner.ID)
s.NotContains(returnedIds, s.deadRunner.ID)
}
const TestNamespace = "unit-tests"