diff options
author | 2024-03-25 18:05:14 +0100 | |
---|---|---|
committer | 2024-03-25 17:05:14 +0000 | |
commit | b7b42e832ad711ebb5af5c03e1c8e8a471c6bde0 (patch) | |
tree | 2fbc4188fd3104f141abe590ac7b586d73772e74 /internal/db | |
parent | [bugfix] Avoid empty public/local timeline queries (#2784) (diff) | |
download | gotosocial-b7b42e832ad711ebb5af5c03e1c8e8a471c6bde0.tar.xz |
[feature] Add healthcheck endpoints `/livez` and `/readyz` (#2783)
* [feature] Add healthcheck endpoints `/livez` and `/readyz`
* use select that returns no data
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/basic.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/basic.go | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/internal/db/basic.go b/internal/db/basic.go index 3a8e2af8d..4c27b7ea6 100644 --- a/internal/db/basic.go +++ b/internal/db/basic.go @@ -33,8 +33,8 @@ type Basic interface { // If the database implementation doesn't need to be stopped, this can just return nil. Close() error - // IsHealthy should return nil if the database connection is healthy, or an error if not. - IsHealthy(ctx context.Context) error + // Ready returns nil if the database connection is ready, or an error if not. + Ready(ctx context.Context) error // GetByID gets one entry by its id. In a database like postgres, this might be the 'id' field of the entry, // for other implementations (for example, in-memory) it might just be the key of a map. diff --git a/internal/db/bundb/basic.go b/internal/db/bundb/basic.go index 7b523f309..82212fc42 100644 --- a/internal/db/bundb/basic.go +++ b/internal/db/bundb/basic.go @@ -124,8 +124,14 @@ func (b *basicDB) DropTable(ctx context.Context, i interface{}) error { return err } -func (b *basicDB) IsHealthy(ctx context.Context) error { - return b.db.PingContext(ctx) +func (b *basicDB) Ready(ctx context.Context) error { + if _, err := b.db. + NewRaw("SELECT NULL FROM ? LIMIT 0", bun.Ident("instances")). + Exec(ctx); err != nil { + return err + } + + return nil } func (b *basicDB) Close() error { |