From cab3fc6ac1842e9972ce67179eb81a8b16d6ffd5 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Mon, 19 Feb 2024 14:02:22 +0100 Subject: [PATCH] fix: use a random selection of jobs in the job cleaning procedure --- .../Agent/JobCleaningAgent.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py index 62f621e1c3f..75129180c66 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py @@ -260,18 +260,18 @@ def _getJobsList(self, condDict, delay=None): :param dict condDict: a dict like {'JobType': 'User', 'Status': 'Killed'} :param int delay: days of delay - :returns: S_OK with jobsList + :returns: S_OK with a list of job IDs """ - jobIDsS = set() + delayStr = f"and older than {delay}" if delay else "" self.log.info(f"Get jobs with {str(condDict)} {delayStr}") - for order in ["JobID:ASC", "JobID:DESC"]: - result = self.jobDB.selectJobs(condDict, older=delay, orderAttribute=order, limit=self.maxJobsAtOnce) - if not result["OK"]: - return result - jobIDsS = jobIDsS.union({int(jID) for jID in result["Value"]}) - return S_OK(list(jobIDsS)) + # Select a random set of jobs + result = self.jobDB.selectJobs(condDict, older=delay, orderAttribute="RAND()", limit=self.maxJobsAtOnce) + if not result["OK"]: + return result + + return S_OK(result["Value"]) def _getOwnerJobsDict(self, jobList): """