From 30add04ee4f0033451ed5bc0b2b25ecc66eac527 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 16 Jul 2024 22:03:53 -0700 Subject: [PATCH] fix: only poll for deployment changes when needed --- backend/controller/controller.go | 2 ++ backend/controller/dal/dal.go | 5 ++--- backend/controller/dal/notify.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 56b887c4a4..4208993e8a 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -1552,6 +1552,8 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon s.dal.DeploymentChanges.Subscribe(deploymentChanges) defer s.dal.DeploymentChanges.Unsubscribe(deploymentChanges) + go s.dal.PollDeployments(ctx) + for { select { case <-ctx.Done(): diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index b72c0ed297..daddfa85f6 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -214,13 +214,13 @@ func WithReservation(ctx context.Context, reservation Reservation, fn func() err func New(ctx context.Context, pool *pgxpool.Pool) (*DAL, error) { _, err := pool.Acquire(ctx) if err != nil { - return nil, fmt.Errorf("failed to acquire PG PubSub connection: %w", err) + return nil, fmt.Errorf("could not acquire connection: %w", err) } dal := &DAL{ db: sql.NewDB(pool), DeploymentChanges: pubsub.New[DeploymentNotification](), } - go dal.pollDeployments(ctx) + return dal, nil } @@ -233,7 +233,6 @@ type DAL struct { // DeploymentChanges is a Topic that receives changes to the deployments table. DeploymentChanges *pubsub.Topic[DeploymentNotification] - // RouteChanges is a Topic that receives changes to the routing table. } // Tx is DAL within a transaction. diff --git a/backend/controller/dal/notify.go b/backend/controller/dal/notify.go index 62fe034f5d..e76d3d13d0 100644 --- a/backend/controller/dal/notify.go +++ b/backend/controller/dal/notify.go @@ -72,7 +72,7 @@ func deploymentStateFromDeployment(deployment Deployment) (deploymentState, erro }, nil } -func (d *DAL) pollDeployments(ctx context.Context) { +func (d *DAL) PollDeployments(ctx context.Context) { logger := log.FromContext(ctx) retry := backoff.Backoff{}