mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-03 19:47:14 +08:00
Get rid of the S3 scheduler
This commit is contained in:
parent
c09d277678
commit
56ef175646
@ -41,7 +41,6 @@ const secondsPerDay = 60 * 60 * 24
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
scheduler = cron.New(cron.WithLocation(time.UTC))
|
scheduler = cron.New(cron.WithLocation(time.UTC))
|
||||||
s3scheduler = cron.New(cron.WithLocation(time.UTC))
|
|
||||||
secret []byte
|
secret []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,12 +91,14 @@ func Init() error {
|
|||||||
scheduler.Start()
|
scheduler.Start()
|
||||||
|
|
||||||
if os.Getenv("AWS_ENDPOINT_URL_S3") != "" {
|
if os.Getenv("AWS_ENDPOINT_URL_S3") != "" {
|
||||||
_, err = s3scheduler.AddFunc("@hourly", S3SaveMigration)
|
go func() {
|
||||||
|
for {
|
||||||
|
err = S3SaveMigration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
s3scheduler.Start()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -116,7 +117,7 @@ func deriveSeed(seedTime time.Time) []byte {
|
|||||||
return hashedSeed[:]
|
return hashedSeed[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func S3SaveMigration() {
|
func S3SaveMigration() error {
|
||||||
cfg, _ := config.LoadDefaultConfig(context.TODO())
|
cfg, _ := config.LoadDefaultConfig(context.TODO())
|
||||||
|
|
||||||
svc := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
svc := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
||||||
@ -128,13 +129,12 @@ func S3SaveMigration() {
|
|||||||
Bucket: aws.String("pokerogue-system"),
|
Bucket: aws.String("pokerogue-system"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error while creating bucket: %s", err)
|
log.Printf("error while creating bucket (already exists?): %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts, err := db.RetrieveOldAccounts()
|
accounts, err := db.RetrieveOldAccounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to retrieve old accounts")
|
return fmt.Errorf("failed to retrieve old accounts: %s", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range accounts {
|
for _, user := range accounts {
|
||||||
@ -165,10 +165,12 @@ func S3SaveMigration() {
|
|||||||
|
|
||||||
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)
|
log.Printf("failed to update location for user %s: %s", username, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Saved data in S3 for user %s", username)
|
log.Printf("saved data in S3 for user %s", username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user