Change more stuff

styling-fixes
Pancakes 1 month ago
parent 00e783ff8a
commit c09d277678
No known key found for this signature in database
GPG Key ID: 5792877BFA27DC8F

@ -91,18 +91,15 @@ func Init() error {
scheduler.Start() scheduler.Start()
if os.Getenv("AWS_ENDPOINT_URL_S3") == "" { if os.Getenv("AWS_ENDPOINT_URL_S3") != "" {
log.Printf("AWS_ENDPOINT_URL_S3 not set, skipping s3 migration") _, err = s3scheduler.AddFunc("@hourly", S3SaveMigration)
return nil if err != nil {
} return err
}
_, err = s3scheduler.AddFunc("@hourly", S3SaveMigration) s3scheduler.Start()
if err != nil {
return err
} }
s3scheduler.Start()
return nil return nil
} }
@ -162,15 +159,16 @@ func S3SaveMigration() {
Body: bytes.NewReader(json), Body: bytes.NewReader(json),
}) })
if err != nil { 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 continue
} }
err = db.UpdateLocation(user, username) err = db.UpdateLocation(user, username)
if err != nil { if err != nil {
log.Printf("Failed to update location for user %s: %s", username, err)
continue continue
} }
fmt.Printf("Saved data in s3 for user %s\n", username) log.Printf("Saved data in S3 for user %s", username)
} }
} }

@ -420,8 +420,7 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
http.Error(w, err.Error(), http.StatusNotFound) http.Error(w, err.Error(), http.StatusNotFound)
} else { } else {
fmt.Printf("failed to get system save data: %s\n", err) httpError(w, r, fmt.Errorf("failed to get system save data: %s", err), http.StatusInternalServerError)
httpError(w, r, err, http.StatusInternalServerError)
} }
return return

@ -22,7 +22,7 @@ import (
"context" "context"
"encoding/gob" "encoding/gob"
"encoding/json" "encoding/json"
"fmt" "log"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"github.com/pagefaultgames/rogueserver/defs" "github.com/pagefaultgames/rogueserver/defs"
@ -250,11 +250,11 @@ func RetrieveSystemSaveFromS3(uuid []byte) error {
err = StoreSystemSaveData(uuid, session) err = StoreSystemSaveData(uuid, session)
if err != nil { 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 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) _, err = handle.Exec("UPDATE accounts SET isInLocalDb = 1 WHERE uuid = ?", uuid)
if err != nil { if err != nil {
@ -266,7 +266,7 @@ func RetrieveSystemSaveFromS3(uuid []byte) error {
Key: aws.String(username), Key: aws.String(username),
}) })
if err != nil { 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 return nil
@ -297,7 +297,6 @@ func RetrieveOldAccounts() ([][]byte, error) {
func UpdateLocation(uuid []byte, username string) error { func UpdateLocation(uuid []byte, username string) error {
_, err := handle.Exec("UPDATE accounts SET isInLocalDb = 0 WHERE uuid = ?", uuid) _, err := handle.Exec("UPDATE accounts SET isInLocalDb = 0 WHERE uuid = ?", uuid)
if err != nil { if err != nil {
fmt.Printf("Failed to update location for user %s\n", username)
return err return err
} }

Loading…
Cancel
Save