MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / NewRegistry

Function NewRegistry

server-source-code/internal/context/registry.go:49–79  ·  view source on GitHub ↗

NewRegistry connects to the registry DB and starts a background poller.

(ctx stdctx.Context, databaseURL string, pollInterval time.Duration, log *slog.Logger)

Source from the content-addressed store, hash-verified

47
48// NewRegistry connects to the registry DB and starts a background poller.
49func NewRegistry(ctx stdctx.Context, databaseURL string, pollInterval time.Duration, log *slog.Logger) (*Registry, error) {
50 if databaseURL == "" {
51 return nil, nil
52 }
53 cfg, err := pgxpool.ParseConfig(databaseURL)
54 if err != nil {
55 return nil, err
56 }
57 pool, err := pgxpool.NewWithConfig(ctx, cfg)
58 if err != nil {
59 return nil, err
60 }
61 if err := pool.Ping(ctx); err != nil {
62 pool.Close()
63 return nil, err
64 }
65 r := &Registry{
66 pool: pool,
67 byHost: make(map[string]*Entry),
68 pollDur: pollInterval,
69 stop: make(chan struct{}),
70 stopped: make(chan struct{}),
71 log: log,
72 }
73 if err := r.refresh(ctx); err != nil {
74 pool.Close()
75 return nil, err
76 }
77 go r.poll()
78 return r, nil
79}
80
81// Close stops the poller and closes the pool.
82func (r *Registry) Close() {

Callers

nothing calls this directly

Calls 4

refreshMethod · 0.95
pollMethod · 0.95
PingMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected