feat: add database configuration and initialize scheduler service#83
Conversation
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant Main
participant Config
participant PostgresBackend
participant SchedulerService
participant AsynqClient
participant AsynqServer
Main->>Config: Load PayrollWorkerConfig (with Database.DSN)
Main->>PostgresBackend: Initialize using Config.Database.DSN
Main->>AsynqClient: Initialize Asynq client
Main->>SchedulerService: Create with PostgresBackend, AsynqClient, Redis options
Main->>SchedulerService: Start
Main->>AsynqServer: Configure with new scheduled_plugin_queue
Note over Main: Defer SchedulerService.Stop on exit
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package session: could not load export data: no export data for "github.com/vultisig/go-wrappers/go-dkls/sessions"" ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
Adds database configuration support and initializes a scheduler service in the payroll worker.
- Introduce
Database.DSNin config to load Postgres connection - Wire up
postgres.NewPostgresBackendandscheduler.NewSchedulerServiceinmain.go - Start and stop the scheduler service alongside existing task handlers
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/payroll/worker/config.go | Added Database struct with DSN field |
| cmd/payroll/worker/main.go | Imported scheduler and Postgres modules, created backend, initialized scheduler, and started service |
Comments suppressed due to low confidence (1)
cmd/payroll/worker/main.go:55
- Typo in variable name 'postgressDB'; consider renaming to 'postgresDB' to accurately reflect the Postgres backend.
postgressDB, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cmd/payroll/worker/main.go (1)
55-58: Consider adding DSN validation.The Postgres backend initialization is correctly implemented with proper error handling. However, consider validating that
cfg.Database.DSNis not empty before attempting to create the backend to provide clearer error messages.+ if cfg.Database.DSN == "" { + panic(fmt.Errorf("database DSN is required but not configured")) + } postgressDB, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil) if err != nil { panic(fmt.Errorf("failed to create postgres backend: %w", err)) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
cmd/payroll/worker/config.go(1 hunks)cmd/payroll/worker/main.go(2 hunks)
🔇 Additional comments (4)
cmd/payroll/worker/config.go (1)
21-23: LGTM! Database configuration follows established patterns.The Database struct addition is well-structured and consistent with other configuration fields in the struct. The
mapstructureandjsontags are properly configured for configuration unmarshalling.cmd/payroll/worker/main.go (3)
11-13: LGTM! Import additions are appropriate.The new imports for
schedulerandpostgrespackages align with the functionality being added and follow the existing import organization pattern.
47-47: LGTM! New queue configuration is consistent.The addition of
"scheduled_plugin_queue"with concurrency 10 follows the same pattern as the existing queue configuration and is appropriately named for its purpose.
59-64: LGTM! Scheduler service lifecycle is properly managed.The scheduler service creation, initialization, and cleanup are well-implemented:
- Proper error handling with descriptive error messages
- Service is started immediately after creation
- Cleanup is ensured with
defer schedulerSvc.Stop()- Follows the same error handling pattern as other services
Summary by CodeRabbit