Skip to content

Commit

Permalink
fix: cache migration status (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 1, 2022
1 parent 4e8a8c1 commit 9020738
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sync"
"time"

"github.com/ory/x/popx"

"github.com/hashicorp/go-retryablehttp"

"github.com/ory/x/httpx"
Expand Down Expand Up @@ -83,7 +85,8 @@ type RegistryDefault struct {
healthxHandler *healthx.Handler
metricsHandler *prometheus.Handler

persister persistence.Persister
persister persistence.Persister
migrationStatus popx.MigrationStatuses

hookVerifier *hook.Verifier
hookSessionIssuer *hook.SessionIssuer
Expand Down Expand Up @@ -222,6 +225,10 @@ func (m *RegistryDefault) HealthHandler(_ context.Context) *healthx.Handler {
return m.Ping()
},
"migrations": func(r *http.Request) error {
if m.migrationStatus != nil && !m.migrationStatus.HasPending() {
return nil
}

status, err := m.Persister().MigrationStatus(r.Context())
if err != nil {
return err
Expand All @@ -231,6 +238,7 @@ func (m *RegistryDefault) HealthHandler(_ context.Context) *healthx.Handler {
return errors.Errorf("migrations have not yet been fully applied")
}

m.migrationStatus = status
return nil
},
})
Expand Down

0 comments on commit 9020738

Please sign in to comment.