-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrations.go
48 lines (38 loc) · 1.17 KB
/
registrations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package health
import (
"context"
"github.com/alexfalkowski/go-health/checker"
"github.com/alexfalkowski/go-health/server"
"github.com/alexfalkowski/go-service/health"
mhealth "github.com/alexfalkowski/migrieren/health"
"github.com/alexfalkowski/migrieren/migrate"
"github.com/alexfalkowski/migrieren/migrate/migrator"
"go.uber.org/fx"
)
// Params for health.
type Params struct {
fx.In
Health *mhealth.Config
Migrate *migrate.Config
Migrator migrator.Migrator
}
// NewRegistrations for health.
func NewRegistrations(params Params) health.Registrations {
registrations := health.Registrations{
server.NewRegistration("noop", params.Health.Duration, checker.NewNoopChecker()),
}
for _, d := range params.Migrate.Databases {
checker := &migratorChecker{config: d, migrator: params.Migrator}
reg := server.NewRegistration(d.Name, params.Health.Duration, checker)
registrations = append(registrations, reg)
}
return registrations
}
type migratorChecker struct {
config migrate.Database
migrator migrator.Migrator
}
// Check the migrator.
func (c *migratorChecker) Check(ctx context.Context) error {
return c.migrator.Ping(ctx, c.config.Source, c.config.URL)
}