From 261dae2604fa65fb00f070a34de5c0b40809ce65 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 22 Sep 2023 07:27:44 -0400 Subject: [PATCH] feat(workers): prevent redundant scalers computation on published manifest event. Signed-off-by: Ahmed --- src/scaler/manager.rs | 7 +++++-- src/workers/event.rs | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/scaler/manager.rs b/src/scaler/manager.rs index e8297f90..4877b9ae 100644 --- a/src/scaler/manager.rs +++ b/src/scaler/manager.rs @@ -248,8 +248,11 @@ where /// This only constructs the scalers and doesn't reconcile. The returned [`Scalers`] type can be /// used to set this model to backoff mode #[instrument(level = "trace", skip_all, fields(name = %manifest.metadata.name, lattice_id = %self.lattice_id))] - pub async fn add_scalers<'a>(&'a self, manifest: &'a Manifest) -> Result { - let scalers = self.scalers_for_manifest(manifest); + pub async fn add_scalers<'a>( + &'a self, + manifest: &'a Manifest, + scalers: ScalerList, + ) -> Result { self.add_raw_scalers(&manifest.metadata.name, scalers).await; let notification = serde_json::to_vec(&Notifications::CreateScalers(manifest.to_owned()))?; self.client diff --git a/src/workers/event.rs b/src/workers/event.rs index d51f500e..fc11411a 100644 --- a/src/workers/event.rs +++ b/src/workers/event.rs @@ -793,8 +793,7 @@ where // redelivered. When it is, the ones that succeeded will be in backoff mode and the ones // that failed will be retried. - // TODO: inefficient to compute scalers twice, consider refactoring - let scalers = self.scalers.add_scalers(&data.manifest).await?; + let scalers = self.scalers.add_scalers(&data.manifest, scalers).await?; let (commands, res) = get_commands_and_result( scalers.iter().map(|s| s.reconcile()),