Skip to content

Commit

Permalink
feat: add logging support to cleanup manager and engine initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercactapus committed Dec 17, 2024
1 parent f8c555d commit 9ee4383
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/initengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (app *App) initEngine(ctx context.Context) error {
River: app.River,
RiverDBSQL: app.RiverDBSQL,
RiverWorkers: app.RiverWorkers,
Logger: app.Logger,
})
if err != nil {
return errors.Wrap(err, "init engine")
Expand Down
7 changes: 4 additions & 3 deletions engine/cleanupmanager/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type DB struct {
func (db *DB) Name() string { return "Engine.CleanupManager" }

// NewDB creates a new DB.
func NewDB(ctx context.Context, db *sql.DB, alertstore *alert.Store) (*DB, error) {
func NewDB(ctx context.Context, db *sql.DB, alertstore *alert.Store, log *slog.Logger) (*DB, error) {
lock, err := processinglock.NewLock(ctx, db, processinglock.Config{
Version: 1,
Type: processinglock.TypeCleanup,
Expand All @@ -44,8 +44,9 @@ func NewDB(ctx context.Context, db *sql.DB, alertstore *alert.Store) (*DB, error
p := &util.Prepare{Ctx: ctx, DB: db}

return &DB{
db: db,
lock: lock,
db: db,
lock: lock,
logger: log,

// Abort any cleanup operation that takes longer than 3 seconds
// error will be logged.
Expand Down
2 changes: 2 additions & 0 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package engine

import (
"database/sql"
"log/slog"
"time"

"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -49,6 +50,7 @@ type Config struct {

DisableCycle bool
LogCycles bool
Logger *slog.Logger

CycleTime time.Duration
}
3 changes: 2 additions & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log/slog"
"strings"
"time"

Expand Down Expand Up @@ -122,7 +123,7 @@ func NewEngine(ctx context.Context, db *sql.DB, c *Config) (*Engine, error) {
if err != nil {
return nil, errors.Wrap(err, "heartbeat processing backend")
}
cleanMgr, err := cleanupmanager.NewDB(ctx, db, c.AlertStore)
cleanMgr, err := cleanupmanager.NewDB(ctx, db, c.AlertStore, c.Logger.With(slog.String("module", "cleanup")))
if err != nil {
return nil, errors.Wrap(err, "cleanup backend")
}
Expand Down

0 comments on commit 9ee4383

Please sign in to comment.