Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
version: "2"
run:
timeout: 10m
allow-serial-runners: true
concurrency: 0
linters-settings:
goimports:
local-prefixes: github.com/theopenlane/riverboat
gofumpt:
extra-rules: true
gosec:
exclude-generated: true
revive:
ignore-generated-header: true
linters:
enable:
- bodyclose
- errcheck
- err113
- gocritic
- gocyclo
- err113
- gofmt
- goimports
- mnd
- gosimple
- govet
- gosec
- ineffassign
- misspell
- mnd
- noctx
- revive
- staticcheck
- stylecheck
- typecheck
- unused
- whitespace
- wsl
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- .buildkite/*
- .github/*
- docker/*
- third_party$
- builtin$
- examples$
issues:
fix: true
exclude-use-default: true
exclude-dirs:
- .buildkite/*
- .github/*
- docker/*
exclude-files: []
formatters:
enable:
- gofmt
- goimports
settings:
gofumpt:
extra-rules: true
goimports:
local-prefixes:
- github.com/theopenlane/riverboat
exclusions:
generated: lax
paths:
- .buildkite/*
- .github/*
- docker/*
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tasks:
go:lint:
desc: runs golangci-lint, the most annoying opinionated linter ever
cmds:
- golangci-lint run --config=.golangci.yaml --verbose --fast --fix
- golangci-lint run --config=.golangci.yaml --verbose --fix

go:fmt:
desc: format all go code
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var k *koanf.Koanf
var rootCmd = &cobra.Command{
Use: appName,
Short: "A cli for interacting with the riverboat job queue server",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
err := initCmdFlags(cmd)
cobra.CheckErr(err)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var serveCmd = &cobra.Command{
Use: "serve",
Short: "start the riverboat server",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := serve(cmd.Context())
cobra.CheckErr(err)
},
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
container_name: postgres-riverboat
command: postgres -c 'max_connections=150'
ports:
- "5434:5432"
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ services:
ports:
- 8082:8080
environment:
- DATABASE_URL=postgres://postgres:password@host.docker.internal:5434/jobs?sslmode=disable
- DATABASE_URL=postgres://postgres:password@host.docker.internal:5432/jobs?sslmode=disable
networks:
- default
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- --debug
- --pretty
environment:
- RIVERBOAT_JOBQUEUE_DATABASEHOST=postgres://postgres:password@postgres-riverboat:5434/jobs?sslmode=disable
- RIVERBOAT_JOBQUEUE_DATABASEHOST=postgres://postgres:password@postgres-riverboat:5432/jobs?sslmode=disable
restart: unless-stopped
networks:
- default
4 changes: 2 additions & 2 deletions internal/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type Config struct {
}

// Ensure that *Config implements ConfigProvider interface.
var _ ConfigProvider = &Config{}
var _ Provider = &Config{}

// GetConfig implements ConfigProvider.
func (c *Config) GetConfig() (*Config, error) {
func (c *Config) Get() (*Config, error) {
return c, nil
}
8 changes: 4 additions & 4 deletions internal/server/config/configprovider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

// ConfigProvider serves as a common interface to read echo server configuration
type ConfigProvider interface {
// GetConfig returns the server configuration
GetConfig() (*Config, error)
// Provider serves as a common interface to read echo server configuration
type Provider interface {
// Get returns the server configuration
Get() (*Config, error)
}
24 changes: 12 additions & 12 deletions internal/server/config/configproviderrefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import (
"github.com/rs/zerolog/log"
)

// ConfigProviderWithRefresh shows a config provider with automatic refresh; it contains fields and methods to manage the configuration,
// ProviderWithRefresh shows a config provider with automatic refresh; it contains fields and methods to manage the configuration,
// and refresh it periodically based on a specified interval
type ConfigProviderWithRefresh struct {
type ProviderWithRefresh struct {
sync.RWMutex

config *Config

configProvider ConfigProvider
configProvider Provider

refreshInterval time.Duration

ticker *time.Ticker
stop chan bool
}

// NewConfigProviderWithRefresh function is a constructor function that creates a new instance of ConfigProviderWithRefresh
func NewConfigProviderWithRefresh(cfgProvider ConfigProvider) (*ConfigProviderWithRefresh, error) {
cfg, err := cfgProvider.GetConfig()
// NewProviderWithRefresh function is a constructor function that creates a new instance of ProviderWithRefresh
func NewProviderWithRefresh(cfgProvider Provider) (*ProviderWithRefresh, error) {
cfg, err := cfgProvider.Get()
if err != nil {
return nil, err
}

cfgRefresh := &ConfigProviderWithRefresh{
cfgRefresh := &ProviderWithRefresh{
config: cfg,
configProvider: cfgProvider,
refreshInterval: cfg.Settings.RefreshInterval,
Expand All @@ -40,15 +40,15 @@ func NewConfigProviderWithRefresh(cfgProvider ConfigProvider) (*ConfigProviderWi
}

// GetConfig retrieves the current echo server configuration; it acquires a read lock to ensure thread safety and returns the `config` field
func (s *ConfigProviderWithRefresh) GetConfig() (*Config, error) {
func (s *ProviderWithRefresh) Get() (*Config, error) {
s.RLock()
defer s.RUnlock()

return s.config, nil
}

// initialize the config provider with refresh
func (s *ConfigProviderWithRefresh) initialize() {
func (s *ProviderWithRefresh) initialize() {
if s.refreshInterval != 0 {
s.stop = make(chan bool)
s.ticker = time.NewTicker(s.refreshInterval)
Expand All @@ -57,15 +57,15 @@ func (s *ConfigProviderWithRefresh) initialize() {
}
}

func (s *ConfigProviderWithRefresh) refreshConfig() {
func (s *ProviderWithRefresh) refreshConfig() {
for {
select {
case <-s.stop:
break
case <-s.ticker.C:
}

newConfig, err := s.configProvider.GetConfig()
newConfig, err := s.configProvider.Get()
if err != nil {
log.Error().Msg("failed to load new server configuration")
continue
Expand All @@ -82,7 +82,7 @@ func (s *ConfigProviderWithRefresh) refreshConfig() {
// Close function is used to stop the automatic refresh of the configuration.
// It stops the ticker that triggers the refresh and closes the stop channel,
// which signals the goroutine to stop refreshing the configuration
func (s *ConfigProviderWithRefresh) Close() {
func (s *ProviderWithRefresh) Close() {
if s.ticker != nil {
s.ticker.Stop()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/serveropts/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newApplyFunc(apply func(option *ServerOptions)) *applyFunc {
}

// WithConfigProvider supplies the config for the server
func WithConfigProvider(cfgProvider config.ConfigProvider) ServerOption {
func WithConfigProvider(cfgProvider config.Provider) ServerOption {
return newApplyFunc(func(s *ServerOptions) {
s.ConfigProvider = cfgProvider
})
Expand Down
2 changes: 1 addition & 1 deletion internal/server/serveropts/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type ServerOptions struct {
ConfigProvider serverconfig.ConfigProvider
ConfigProvider serverconfig.Provider
Config serverconfig.Config
}

Expand Down
2 changes: 1 addition & 1 deletion test/common/river.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
devDatabaseHost = "postgres://postgres:password@0.0.0.0:5434/jobs?sslmode=disable"
devDatabaseHost = "postgres://postgres:password@0.0.0.0:5432/jobs?sslmode=disable"
)

func NewInsertOnlyRiverClient() *river.Client[pgx.Tx] {
Expand Down