Skip to content

Commit

Permalink
fix: postgres db events listener initialization (#1187)
Browse files Browse the repository at this point in the history
The `PullSchema` stream was broken causing issues for things like `ftl
dev` which relies on updates to know when and how to rebuild.

The `LISTEN` needs to be called on each `topic` we want to listen to so
we added a loop to listen to all topic channels.

Fixes #1182
  • Loading branch information
wesbillman authored Apr 5, 2024
1 parent 366a178 commit 2a1d4d8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions backend/controller/dal/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ func (d *DAL) runListener(ctx context.Context, conn *pgx.Conn) {

// Wait for the notification channel to be ready.
retry := backoff.Backoff{}
for {
_, err := conn.Exec(ctx, "LISTEN notify_events")
if err == nil {
break
channels := []string{"deployments_events", "topics_events", "topic_events_events"}
for _, channel := range channels {
for {
_, err := conn.Exec(ctx, "LISTEN "+channel)
if err == nil {
logger.Debugf("Listening to channel: %s", channel)
retry.Reset()
break
}
logger.Errorf(err, "Failed to LISTEN to %s", channel)
time.Sleep(retry.Duration())
}
logger.Errorf(err, "failed to LISTEN notify_events")
time.Sleep(retry.Duration())
}
retry.Reset()

// Main loop for listening to notifications.
for {
Expand Down

0 comments on commit 2a1d4d8

Please sign in to comment.