Skip to content

Commit

Permalink
fix: only poll for deployment changes when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Jul 17, 2024
1 parent 11c1523 commit 30add04
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
5 changes: 2 additions & 3 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/dal/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 30add04

Please sign in to comment.