Skip to content

Commit

Permalink
Change more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Oct 22, 2024
1 parent 00e783f commit c09d277
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
20 changes: 9 additions & 11 deletions api/daily/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}
3 changes: 1 addition & 2 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions db/savedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"encoding/gob"
"encoding/json"
"fmt"
"log"

"github.com/klauspost/compress/zstd"
"github.com/pagefaultgames/rogueserver/defs"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c09d277

Please sign in to comment.