From c09d27767876b3e6787247a687f962e1b2bd6745 Mon Sep 17 00:00:00 2001 From: Pancakes Date: Tue, 22 Oct 2024 16:12:16 -0400 Subject: [PATCH] Change more stuff --- api/daily/common.go | 20 +++++++++----------- api/endpoints.go | 3 +-- db/savedata.go | 9 ++++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/api/daily/common.go b/api/daily/common.go index 97d897b..c2bc2c6 100644 --- a/api/daily/common.go +++ b/api/daily/common.go @@ -91,18 +91,15 @@ func Init() error { scheduler.Start() - if os.Getenv("AWS_ENDPOINT_URL_S3") == "" { - log.Printf("AWS_ENDPOINT_URL_S3 not set, skipping s3 migration") - return nil - } + if os.Getenv("AWS_ENDPOINT_URL_S3") != "" { + _, err = s3scheduler.AddFunc("@hourly", S3SaveMigration) + if err != nil { + return err + } - _, err = s3scheduler.AddFunc("@hourly", S3SaveMigration) - if err != nil { - return err + s3scheduler.Start() } - s3scheduler.Start() - return nil } @@ -162,15 +159,16 @@ func S3SaveMigration() { Body: bytes.NewReader(json), }) if err != nil { - log.Printf("error while saving data in s3 for user %s: %s", username, err) + log.Printf("error while saving data in S3 for user %s: %s", username, err) continue } err = db.UpdateLocation(user, username) if err != nil { + log.Printf("Failed to update location for user %s: %s", username, err) continue } - fmt.Printf("Saved data in s3 for user %s\n", username) + log.Printf("Saved data in S3 for user %s", username) } } diff --git a/api/endpoints.go b/api/endpoints.go index e6ad46f..478b434 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -420,8 +420,7 @@ func handleSystem(w http.ResponseWriter, r *http.Request) { if errors.Is(err, sql.ErrNoRows) { http.Error(w, err.Error(), http.StatusNotFound) } else { - fmt.Printf("failed to get system save data: %s\n", err) - httpError(w, r, err, http.StatusInternalServerError) + httpError(w, r, fmt.Errorf("failed to get system save data: %s", err), http.StatusInternalServerError) } return diff --git a/db/savedata.go b/db/savedata.go index a0f3df0..1a9488c 100644 --- a/db/savedata.go +++ b/db/savedata.go @@ -22,7 +22,7 @@ import ( "context" "encoding/gob" "encoding/json" - "fmt" + "log" "github.com/klauspost/compress/zstd" "github.com/pagefaultgames/rogueserver/defs" @@ -250,11 +250,11 @@ func RetrieveSystemSaveFromS3(uuid []byte) error { err = StoreSystemSaveData(uuid, session) if err != nil { - fmt.Printf("Failed to store system save data from s3 for user %s\n", username) + log.Printf("Failed to store system save data from s3 for user %s", username) return err } - fmt.Printf("Retrieved system save data from s3 for user %s\n", username) + log.Printf("Retrieved system save data from s3 for user %s", username) _, err = handle.Exec("UPDATE accounts SET isInLocalDb = 1 WHERE uuid = ?", uuid) if err != nil { @@ -266,7 +266,7 @@ func RetrieveSystemSaveFromS3(uuid []byte) error { Key: aws.String(username), }) if err != nil { - fmt.Printf("Failed to delete object %s from s3: %s\n", username, err) + log.Printf("Failed to delete object %s from s3: %s", username, err) } return nil @@ -297,7 +297,6 @@ func RetrieveOldAccounts() ([][]byte, error) { func UpdateLocation(uuid []byte, username string) error { _, err := handle.Exec("UPDATE accounts SET isInLocalDb = 0 WHERE uuid = ?", uuid) if err != nil { - fmt.Printf("Failed to update location for user %s\n", username) return err }