diff options
Diffstat (limited to 'src/endpoint/configured.rs')
-rw-r--r-- | src/endpoint/configured.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index e2dda2c..e82901e 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -246,6 +246,7 @@ impl Endpoint { pub fn utilization(&self) -> f64 { let max_jobs = self.num_max_jobs() as f64; let run_jobs = self.running_jobs() as f64; + trace!("utilization of {}: 100.0 / {} * {}", self.name(), max_jobs, run_jobs); 100.0 / max_jobs * run_jobs } @@ -280,6 +281,24 @@ impl Endpoint { }) } + pub async fn number_of_running_containers(&self) -> Result<usize> { + self.docker + .containers() + .list({ + &shiplift::builder::ContainerListOptions::builder() + .all() + .build() + }) + .await + .map_err(Error::from) + .map(|list| { + list.into_iter() + .inspect(|stat| trace!("stat = {:?}", stat)) + .filter(|stat| stat.state == "running") + .count() + }) + } + pub async fn has_container_with_id(&self, id: &str) -> Result<bool> { self.container_stats() .await? @@ -401,14 +420,16 @@ pub struct EndpointHandle(Arc<Endpoint>); impl EndpointHandle { pub fn new(ep: Arc<Endpoint>) -> Self { - let _ = ep.running_jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + let res = ep.running_jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + trace!("Endpoint {} has one job more: {}", ep.name(), res + 1); EndpointHandle(ep) } } impl Drop for EndpointHandle { fn drop(&mut self) { - let _ = self.0.running_jobs.fetch_sub(1, std::sync::atomic::Ordering::Relaxed); + let res = self.0.running_jobs.fetch_sub(1, std::sync::atomic::Ordering::Relaxed); + trace!("Endpoint {} has one job less: {}", self.0.name(), res - 1); } } |