Skip to content

Commit

Permalink
Change poller interval field to int
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed Jan 17, 2025
1 parent 20009ce commit 3c43ebc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 24 deletions.
8 changes: 3 additions & 5 deletions treatment-service/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package config

import (
"fmt"

Check failure on line 4 in treatment-service/config/config.go

View workflow job for this annotation

GitHub Actions / lint-go

File is not `goimports`-ed (goimports)
"strconv"
"time"

"github.com/caraml-dev/mlp/api/pkg/instrumentation/newrelic"
"github.com/caraml-dev/mlp/api/pkg/instrumentation/sentry"
common_config "github.com/caraml-dev/xp/common/config"
common_mq_config "github.com/caraml-dev/xp/common/messagequeue"
"github.com/caraml-dev/xp/treatment-service/models"
"strconv"
)

type AssignedTreatmentLoggerKind = string
Expand Down Expand Up @@ -96,8 +94,8 @@ type ManagementServiceConfig struct {
}

type ManagementServicePollerConfig struct {
Enabled bool `json:"enabled" default:"false"`
PollInterval time.Duration `json:"poll_interval" default:"30s"`
Enabled bool `json:"enabled" default:"false"`
PollIntervalSeconds int `json:"poll_interval" default:"30"`
}

func (c *Config) GetProjectIds() []models.ProjectId {
Expand Down
12 changes: 5 additions & 7 deletions treatment-service/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package config

import (

Check failure on line 3 in treatment-service/config/config_test.go

View workflow job for this annotation

GitHub Actions / lint-go

File is not `goimports`-ed (goimports)
"testing"
"time"

"github.com/caraml-dev/mlp/api/pkg/instrumentation/newrelic"
"github.com/caraml-dev/mlp/api/pkg/instrumentation/sentry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

common_mq_config "github.com/caraml-dev/xp/common/messagequeue"
)
Expand Down Expand Up @@ -66,8 +64,8 @@ func TestDefaultConfigs(t *testing.T) {
SentryConfig: sentry.Config{Enabled: false, Labels: emptyStringMap},
SegmenterConfig: make(map[string]interface{}),
ManagementServicePollerConfig: ManagementServicePollerConfig{
Enabled: false,
PollInterval: 30 * time.Second,
Enabled: false,
PollIntervalSeconds: 30,
},
}
cfg, err := Load()
Expand Down Expand Up @@ -133,8 +131,8 @@ func TestLoadMultipleConfigs(t *testing.T) {
SentryConfig: sentry.Config{Enabled: true, DSN: "my.amazing.sentry.dsn", Labels: map[string]string{"app": "xp-treatment-service"}},
SegmenterConfig: map[string]interface{}{"s2_ids": map[string]interface{}{"mins2celllevel": 9, "maxs2celllevel": 15}},
ManagementServicePollerConfig: ManagementServicePollerConfig{
Enabled: false,
PollInterval: 30 * time.Second,
Enabled: false,
PollIntervalSeconds: 30,
},
}

Expand Down
4 changes: 0 additions & 4 deletions treatment-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/deepmap/oapi-codegen v1.11.0
github.com/getkin/kin-openapi v0.94.0
github.com/go-chi/chi/v5 v5.0.7
github.com/go-playground/validator/v10 v10.11.1
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
github.com/google/go-cmp v0.6.0
Expand Down Expand Up @@ -104,8 +103,6 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/gofrs/flock v0.8.1 // indirect
Expand Down Expand Up @@ -139,7 +136,6 @@ require (
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down
6 changes: 0 additions & 6 deletions treatment-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,13 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-sql-driver/mysql v1.3.0 h1:pgwjLi/dvffoP9aabwkT3AKpXQM93QARkjFhDDqC1UE=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -604,7 +599,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
github.com/lestrrat-go/blackmagic v1.0.0/go.mod h1:TNgH//0vYSs8VXDCfkZLgIrVTTXQELZffUV0tz3MtdQ=
Expand Down
5 changes: 3 additions & 2 deletions treatment-service/server/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ func NewPoller(pollerConfig config.ManagementServicePollerConfig, localStorage *
}

func (p *Poller) Start() {
ticker := time.NewTicker(p.pollerConfig.PollInterval)
pollInterval := time.Duration(p.pollerConfig.PollIntervalSeconds) * time.Second
ticker := time.NewTicker(pollInterval)
go func() {
for {
select {
case <-ticker.C:
err := p.Refresh()
log.Printf("Polling at %v with interval %v", time.Now(), p.pollerConfig.PollInterval)
log.Printf("Polling at %v with interval %v", time.Now(), pollInterval)
if err != nil {
log.Printf("Error updating local storage: %v", err)
continue
Expand Down

0 comments on commit 3c43ebc

Please sign in to comment.