MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / get_total_cpus_running

Method get_total_cpus_running

codeclash/viewer/app_aws.py:252–299  ·  view source on GitHub ↗

Get total number of vCPUs currently allocated in the compute environment

(self)

Source from the content-addressed store, hash-verified

250 return [self.format_job_for_display(job) for job in jobs]
251
252 def get_total_cpus_running(self) -> int:
253 """Get total number of vCPUs currently allocated in the compute environment"""
254 try:
255 # Get the job queue details to find the compute environment
256 queue_response = self.batch_client.describe_job_queues(jobQueues=[self.job_queue])
257
258 if not queue_response.get("jobQueues"):
259 return 0
260
261 # Get compute environments from the job queue
262 compute_env_orders = queue_response["jobQueues"][0].get("computeEnvironmentOrder", [])
263
264 if not compute_env_orders:
265 return 0
266
267 total_vcpus = 0
268
269 # Get details for each compute environment
270 for env_order in compute_env_orders:
271 compute_env_name = env_order.get("computeEnvironment")
272 if not compute_env_name:
273 continue
274
275 # Extract just the name from the ARN if needed
276 env_name = compute_env_name.split("/")[-1]
277
278 env_response = self.batch_client.describe_compute_environments(computeEnvironments=[env_name])
279
280 for env in env_response.get("computeEnvironments", []):
281 # Get the actual allocated vCPUs from the compute resources
282 compute_resources = env.get("computeResources", {})
283
284 # Use desiredvCpus if available (what's currently allocated)
285 # Otherwise fall back to maxvCpus
286 desired_vcpus = compute_resources.get("desiredvCpus")
287 if desired_vcpus is not None:
288 total_vcpus += desired_vcpus
289 else:
290 # If desired is not available, we can't get current allocation
291 # This might happen with FARGATE environments
292 max_vcpus = compute_resources.get("maxvCpus", 0)
293 total_vcpus += max_vcpus
294
295 return total_vcpus
296
297 except Exception as e:
298 logger.warning(f"Failed to get vCPU information from compute environment: {e}", exc_info=True)
299 return 0

Callers 1

_fetch_batch_jobs_implFunction · 0.95

Calls 1

getMethod · 0.80

Tested by

no test coverage detected