From 53dbc4595e704628f266e1df57eafe6b79df1e54 Mon Sep 17 00:00:00 2001 From: Valerie Walch Date: Thu, 30 Oct 2025 19:16:51 -0400 Subject: [PATCH] made polling time configurable. --- Dockerfile | 7 ++++++- compose.yaml | 5 +++-- config.yaml | 1 + config/config.go | 29 ++++++++++++++++++----------- main.go | 2 +- run.sh | 1 - setup/setupBackgroundSync.go | 5 +++-- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8644ff4..13869e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,10 @@ COPY data ./data COPY web-ui ./web-ui COPY config.yaml key.pem cert.pem main.go rsakey.pem build.sh run.sh ./ -RUN CGO_ENABLED=1 GOOS=linux go build -o dingus-server +ENV CGO_ENABLED=1 +ENV GOOS=linux + +RUN go build -o dingus-server # Optional: # To bind to a TCP port, runtime parameters must be supplied to the docker command. @@ -31,5 +34,7 @@ RUN CGO_ENABLED=1 GOOS=linux go build -o dingus-server # https://docs.docker.com/reference/dockerfile/#expose EXPOSE 443 + + # Run CMD ["/app/run.sh"] diff --git a/compose.yaml b/compose.yaml index dd75259..572a913 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,6 @@ +name: dingus services: - dingus-server: + server: build: . ports: - - "443:443" \ No newline at end of file + - "443:443" diff --git a/config.yaml b/config.yaml index cf2874c..056eae7 100644 --- a/config.yaml +++ b/config.yaml @@ -5,3 +5,4 @@ key_file: key.pem tag_id_field_name: Door Key training_field_name: Safety Training wild_apricot_account_id: 232582 +poll_time_mins: 1 diff --git a/config/config.go b/config/config.go index 6622116..11c041c 100644 --- a/config/config.go +++ b/config/config.go @@ -18,17 +18,18 @@ var ( ) type Config struct { - CertFile string `mapstructure:"cert_file" json:"cert_file"` - DatabasePath string `mapstructure:"database_path" json:"database_path"` - KeyFile string `mapstructure:"key_file" json:"key_file"` - TagIdFieldName string `mapstructure:"tag_id_field_name" json:"tag_id_field_name"` - TrainingFieldName string `mapstructure:"training_field_name" json:"training_field_name"` - WildApricotAccountId int `mapstructure:"wild_apricot_account_id" json:"wild_apricot_account_id"` - ContactFilterQuery string `mapstructure:"contact_filter_query" json:"contact_filter_query"` - SSOClientID string `mapstructure:"sso_client_id" json:"sso_client_id"` - SSOClientSecret string `mapstructure:"sso_client_secret" json:"sso_client_secret"` - SSORedirectURI string `mapstructure:"sso_redirect_uri" json:"sso_redirect_uri"` - CookieStoreSecret string `mapstructure:"cookie_store_secret" json:"cookie_store_secret"` + CertFile string `mapstructure:"cert_file" json:"cert_file"` + DatabasePath string `mapstructure:"database_path" json:"database_path"` + KeyFile string `mapstructure:"key_file" json:"key_file"` + TagIdFieldName string `mapstructure:"tag_id_field_name" json:"tag_id_field_name"` + TrainingFieldName string `mapstructure:"training_field_name" json:"training_field_name"` + WildApricotAccountId int `mapstructure:"wild_apricot_account_id" json:"wild_apricot_account_id"` + ContactFilterQuery string `mapstructure:"contact_filter_query" json:"contact_filter_query"` + SSOClientID string `mapstructure:"sso_client_id" json:"sso_client_id"` + SSOClientSecret string `mapstructure:"sso_client_secret" json:"sso_client_secret"` + SSORedirectURI string `mapstructure:"sso_redirect_uri" json:"sso_redirect_uri"` + CookieStoreSecret string `mapstructure:"cookie_store_secret" json:"cookie_store_secret"` + PollTimeMins float32 `mapstructure:"poll_time_mins" json:"poll_time_mins" default:"5.0"` WildApricotApiKey string WildApricotWebhookToken string RFIDFieldName string @@ -60,10 +61,16 @@ func loadConfig() interface{} { } var cfg Config + + // Set default values + cfg.PollTimeMins = 10.0 + if err := viper.Unmarshal(&cfg); err != nil { log.Fatalf("Error unmarshalling config file: %s", err) } + log.Printf("poll_time_mins: %.1f", cfg.PollTimeMins) + // Resolve relative paths cfg.CertFile = filepath.Join(projectRoot, cfg.CertFile) if _, err := os.Stat(cfg.CertFile); os.IsNotExist(err) { diff --git a/main.go b/main.go index 62d1831..b1150c5 100644 --- a/main.go +++ b/main.go @@ -88,7 +88,7 @@ func main() { waService := services.NewWildApricotService(cfg, logger) dbService := services.NewDBService(db, cfg, logger) - setup.StartBackgroundDatabaseUpdate(waService, dbService, logger) + setup.StartBackgroundDatabaseUpdate(waService, dbService, cfg, logger) err = router.RunTLS(":443", cfg.CertFile, cfg.KeyFile) if err != nil { diff --git a/run.sh b/run.sh index d30ff8f..d70e998 100644 --- a/run.sh +++ b/run.sh @@ -5,7 +5,6 @@ export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87 export WILD_APRICOT_SSO_CLIENT_ID=654628fgDFc68hH export WILD_APRICOT_SSO_CLIENT_SECRET=07pb835b7pw3s8r0qrvmtlipuwjtt6 export WILD_APRICOT_SSO_REDIRECT_URI=https://dingus.hackpgh.org/web-ui/home -#export WILD_APRICOT_SSO_REDIRECT_URI=https://localhost/web-ui/home export LOG_LEVEL=INFO export COOKIE_STORE_SECRET=cookiestoresecret export CGO_ENABLED=1 diff --git a/setup/setupBackgroundSync.go b/setup/setupBackgroundSync.go index e372897..6964f1a 100644 --- a/setup/setupBackgroundSync.go +++ b/setup/setupBackgroundSync.go @@ -3,16 +3,17 @@ package setup import ( + "rfid-backend/config" "rfid-backend/services" "time" "github.com/sirupsen/logrus" ) -func StartBackgroundDatabaseUpdate(waService *services.WildApricotService, dbService *services.DBService, logger *logrus.Logger) { +func StartBackgroundDatabaseUpdate(waService *services.WildApricotService, dbService *services.DBService, cfg *config.Config, logger *logrus.Logger) { go func() { updateEntireDatabaseFromWildApricot(waService, dbService, logger) - ticker := time.NewTicker(30 * time.Minute) + ticker := time.NewTicker(time.Duration(cfg.PollTimeMins) * time.Minute) for range ticker.C { updateEntireDatabaseFromWildApricot(waService, dbService, logger) }