diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-05 22:07:30 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-06 09:16:14 +0100 |
commit | 350a324ec5e141eb3da1d01c83be51dae7e43fe1 (patch) | |
tree | add6d1cd33bcf40895a40382e85ff85403b59b7f /src/endpoint/configured.rs | |
parent | 1a6226d30a900e3773c280a20ca985080ba4cb94 (diff) |
Change to not track endpoint load in butido
This patch changes the implementation of the ConfiguredEndpoint and the
EndpointScheduler to not keep track about how many containers are there
running, but to ask the endpoint about the number of running containers
and distribute load always to the one with the least number of
containers.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/endpoint/configured.rs')
-rw-r--r-- | src/endpoint/configured.rs | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index f48e621..bfa2907 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -34,30 +34,16 @@ pub struct ConfiguredEndpoint { speed: usize, #[getset(get_copy = "pub")] - num_current_jobs: usize, - - #[getset(get_copy = "pub")] num_max_jobs: usize, } impl Debug for ConfiguredEndpoint { fn fmt(&self, f: &mut Formatter) -> std::result::Result<(), std::fmt::Error> { - write!(f, - "ConfiguredEndpoint({}, {}/{})", - self.name, - self.num_current_jobs, - self.num_max_jobs) + write!(f, "ConfiguredEndpoint({}, max: {})", self.name, self.num_max_jobs) } } impl ConfiguredEndpoint { - pub fn inc_current_jobs(&mut self) { - self.num_current_jobs += 1; - } - - pub fn dec_current_jobs(&mut self) { - self.num_current_jobs -= 1; - } pub(in super) async fn setup(epc: EndpointConfiguration) -> Result<Self> { let ep = ConfiguredEndpoint::setup_endpoint(epc.endpoint())?; @@ -87,7 +73,6 @@ impl ConfiguredEndpoint { .name(ep.name().clone()) .docker(docker) .speed(ep.speed()) - .num_current_jobs(0) .num_max_jobs(ep.maxjobs()) .build() }) @@ -98,7 +83,6 @@ impl ConfiguredEndpoint { ConfiguredEndpoint::builder() .name(ep.name().clone()) .speed(ep.speed()) - .num_current_jobs(0) .num_max_jobs(ep.maxjobs()) .docker(shiplift::Docker::unix(ep.uri())) .build() @@ -228,6 +212,14 @@ impl ConfiguredEndpoint { .await } + pub async fn number_of_running_containers(&self) -> Result<usize> { + self.docker + .containers() + .list(&Default::default()) + .await + .map_err(Error::from) + .map(|list| list.len()) + } } |