From 3fa33443065800af0819ee185b9753c9e6b6ddd3 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 11 Mar 2024 00:01:42 +0100 Subject: [PATCH 1/4] enabled the mensa cron as an experiment --- deployment/charts/backend/templates/deployments/backend-v2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/charts/backend/templates/deployments/backend-v2.yaml b/deployment/charts/backend/templates/deployments/backend-v2.yaml index eacfbd10..6a04bfd7 100644 --- a/deployment/charts/backend/templates/deployments/backend-v2.yaml +++ b/deployment/charts/backend/templates/deployments/backend-v2.yaml @@ -44,7 +44,7 @@ spec: - name: ENVIRONMENT value: prod - name: MensaCronDisabled - value: "true" + value: "false" - name: APNS_P8_FILE_PATH value: /etc/apns_auth_key.p8 - name: OMDB_API_KEY From 354234b7fca0e6e2355d0b80ef0e46c53273de8f Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 11 Mar 2024 00:30:09 +0100 Subject: [PATCH 2/4] fixed a wrong id name causing db errors --- server/backend/cron/dish_name_download.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/backend/cron/dish_name_download.go b/server/backend/cron/dish_name_download.go index e02e0e28..947321f1 100644 --- a/server/backend/cron/dish_name_download.go +++ b/server/backend/cron/dish_name_download.go @@ -99,7 +99,8 @@ func downloadDailyDishes(c *CronService) { var dishId int64 if err := c.db.Model(&model.Dish{}). Where("name = ? AND cafeteriaID = ?", dish.Name, dish.CafeteriaID). - Select("CanteenDish").First(&dishId). + Select("dish"). + First(&dishId). Count(&count).Error; err != nil { log.WithError(err).Error("Error while checking whether this is already in database") } From aa1427e9d9dd55aa67fbbc52a5d1dd43eb27b462 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 11 Mar 2024 01:00:52 +0100 Subject: [PATCH 3/4] removed the environment.go by inlining the 34chars of code into the only usage --- server/env/environment.go | 19 ------------------- server/utils/telemetry.go | 3 +-- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 server/env/environment.go diff --git a/server/env/environment.go b/server/env/environment.go deleted file mode 100644 index 0526d478..00000000 --- a/server/env/environment.go +++ /dev/null @@ -1,19 +0,0 @@ -package env - -import "os" - -func GetEnvironment() string { - return os.Getenv("ENVIRONMENT") -} - -func IsDev() bool { - return GetEnvironment() == "dev" -} - -func IsProd() bool { - return GetEnvironment() == "prod" -} - -func IsMensaCronActive() bool { - return os.Getenv("MensaCronDisabled") != "true" -} diff --git a/server/utils/telemetry.go b/server/utils/telemetry.go index fd0ecf66..f1d27545 100644 --- a/server/utils/telemetry.go +++ b/server/utils/telemetry.go @@ -3,7 +3,6 @@ package utils import ( "os" - "github.com/TUM-Dev/Campus-Backend/server/env" "github.com/getsentry/sentry-go" "github.com/makasim/sentryhook" log "github.com/sirupsen/logrus" @@ -15,7 +14,7 @@ import ( func SetupTelemetry(Version string) { environment := "development" log.SetLevel(log.TraceLevel) - if env.IsProd() { + if os.Getenv("ENVIRONMENT") == "prod" { log.SetLevel(log.InfoLevel) environment = "production" log.SetFormatter(&log.JSONFormatter{}) // simpler to query but harder to parse in the console From a0e877bf67364d26db319b2c8e19e22ea523e0fe Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 11 Mar 2024 01:01:45 +0100 Subject: [PATCH 4/4] removed the previously deactivated `dishNameDownload`-Cronjob --- .../charts/backend/templates/deployments/backend-v2.yaml | 2 -- docker-compose.yaml | 1 - server/backend/cron/cronjobs.go | 7 +------ 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/deployment/charts/backend/templates/deployments/backend-v2.yaml b/deployment/charts/backend/templates/deployments/backend-v2.yaml index 6a04bfd7..6d10351a 100644 --- a/deployment/charts/backend/templates/deployments/backend-v2.yaml +++ b/deployment/charts/backend/templates/deployments/backend-v2.yaml @@ -43,8 +43,6 @@ spec: env: - name: ENVIRONMENT value: prod - - name: MensaCronDisabled - value: "false" - name: APNS_P8_FILE_PATH value: /etc/apns_auth_key.p8 - name: OMDB_API_KEY diff --git a/docker-compose.yaml b/docker-compose.yaml index e876f031..4b90d942 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,7 +15,6 @@ services: - APNS_KEY_ID=${APNS_KEY_ID} - APNS_TEAM_ID=${APNS_TEAM_ID} - APNS_P8_FILE_PATH=${APNS_P8_FILE_PATH} - - MensaCronDisabled=true - OMDB_API_KEY=${OMDB_API_KEY} - CAMPUS_API_TOKEN=${CAMPUS_API_TOKEN} - SMTP_PASSWORD=${SMTP_PASSWORD} diff --git a/server/backend/cron/cronjobs.go b/server/backend/cron/cronjobs.go index 75f4752d..0d18816b 100644 --- a/server/backend/cron/cronjobs.go +++ b/server/backend/cron/cronjobs.go @@ -3,8 +3,6 @@ package cron import ( "time" - "github.com/TUM-Dev/Campus-Backend/server/env" - "github.com/TUM-Dev/Campus-Backend/server/model" "github.com/mmcdole/gofeed" log "github.com/sirupsen/logrus" @@ -42,7 +40,6 @@ func New(db *gorm.DB) *CronService { } func (c *CronService) Run() error { - log.WithField("MensaCronActive", env.IsMensaCronActive()).Debug("running cron service") for { g := new(errgroup.Group) log.Trace("Cron: checking for pending") @@ -78,9 +75,7 @@ func (c *CronService) Run() error { case FileDownloadType: g.Go(func() error { return c.fileDownloadCron() }) case DishNameDownload: - if env.IsMensaCronActive() { - g.Go(c.dishNameDownloadCron) - } + g.Go(func() error { return c.dishNameDownloadCron() }) case MovieType: g.Go(func() error { return c.movieCron() }) /*