mirror of
				https://gitlab.cs.uni-saarland.de/hpc/cc-condor-sync.git
				synced 2025-10-30 08:45:07 +01:00 
			
		
		
		
	Make stop script more robust.
And handle pagination.
This commit is contained in:
		| @@ -35,12 +35,21 @@ class CCApi: | |||||||
|     def getJobs(self, filter_running=True): |     def getJobs(self, filter_running=True): | ||||||
|         url = self.apiurl+"jobs/" |         url = self.apiurl+"jobs/" | ||||||
|         if filter_running: |         if filter_running: | ||||||
|             url = url+"?state=running" |             url = url+"?state=running&items-per-page=100" | ||||||
|         r = requests.get(url, headers=self.headers) |         jobs = [] | ||||||
|         if r.status_code == 200: |         page = 1 | ||||||
|             return r.json()['jobs'] |         while True: | ||||||
|         else: |             r = requests.get(url + "&page=%d" % page, headers=self.headers) | ||||||
|             return [] |             page += 1 | ||||||
|  |             if r.status_code == 200: | ||||||
|  |                 new_jobs = r.json()['jobs'] | ||||||
|  |                 if len(new_jobs) < 100: | ||||||
|  |                     jobs.extend(new_jobs) | ||||||
|  |                     return jobs | ||||||
|  |                 else: | ||||||
|  |                     jobs.extend(new_jobs) | ||||||
|  |             else: | ||||||
|  |                 return [] | ||||||
|  |  | ||||||
|     def _getSubmitNodeId(self, globalJobId): |     def _getSubmitNodeId(self, globalJobId): | ||||||
|         job_id_parts = globalJobId.split('#') |         job_id_parts = globalJobId.split('#') | ||||||
| @@ -95,11 +104,12 @@ if __name__ == "__main__": | |||||||
|     cc = CCApi(config, args.debug) |     cc = CCApi(config, args.debug) | ||||||
|  |  | ||||||
|     condor_jobs = subprocess.run( |     condor_jobs = subprocess.run( | ||||||
|         ["ssh", "conduit2.cs.uni-saarland.de", "condor_q", "-json", "-all", "-glob"], capture_output=True, text=True).stdout |         ["ssh", "conduit2.cs.uni-saarland.de", "condor_q", "-json", "-all", "-glob", "-constraint", "\"JobStatus == 2\""], capture_output=True, text=True).stdout | ||||||
|     running_jobs = json.loads(condor_jobs) |     running_jobs = json.loads(condor_jobs) | ||||||
|      |      | ||||||
|     cc_jobs = cc.getJobs() |     cc_jobs = cc.getJobs() | ||||||
|     running_job_dict = {cc._jobIdToInt(job['GlobalJobId']): (job['GlobalJobId'], job['EnteredCurrentStatus']) for job in running_jobs} |     running_job_dict = {cc._jobIdToInt(job['GlobalJobId']): (job['GlobalJobId'], job['JobCurrentStartDate']) for job in running_jobs} | ||||||
|  |     print("CC jobs:", len(cc_jobs), " Condor jobs:", len(running_job_dict)) | ||||||
|     for cc_job in cc_jobs: |     for cc_job in cc_jobs: | ||||||
|         startTime = cc_job['startTime'] |         startTime = cc_job['startTime'] | ||||||
|         if not cc_job['jobId'] in running_job_dict or abs(startTime - running_job_dict[cc_job['jobId']][1]) > 5: |         if not cc_job['jobId'] in running_job_dict or abs(startTime - running_job_dict[cc_job['jobId']][1]) > 5: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user