Add retry logic
This commit is contained in:
parent
0b9a8e4ca1
commit
e76354651c
@ -4,9 +4,12 @@ import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.itzana.me/itzaname/go-roblox"
|
||||
"git.itzana.me/itzaname/rbxcompiler/internal/rbxbuilder"
|
||||
"os"
|
||||
)
|
||||
|
||||
var script = flag.Bool("script", false, "If the target is a script.")
|
||||
@ -16,6 +19,8 @@ var input = flag.String("input", "", "Input path.")
|
||||
var assetId = flag.Int("asset", 0, "Upload asset ID")
|
||||
var groupId = flag.Int("group", 0, "Group ID")
|
||||
var doGenerate = flag.Bool("generate", false, "If a place file should be dumped")
|
||||
var maxRetries = 5
|
||||
var baseDelay = 1 * time.Second
|
||||
|
||||
func build() {
|
||||
settings := &rbxbuilder.BuildSettings{
|
||||
@ -52,10 +57,22 @@ func build() {
|
||||
fmt.Printf("Logged in as %s...\n", rbx.Username)
|
||||
fmt.Printf("Uploading file to roblox...\n")
|
||||
|
||||
id, err := rbx.CreateAsset(&roblox.AssetUploadOptions{
|
||||
AssetID: *assetId,
|
||||
Group: *groupId,
|
||||
}, buffer)
|
||||
var id int
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
id, err = rbx.CreateAsset(&roblox.AssetUploadOptions{
|
||||
AssetID: *assetId,
|
||||
Group: *groupId,
|
||||
}, buffer)
|
||||
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
backoffSec := math.Pow(2, float64(i))
|
||||
fmt.Printf("Upload failed. Will try in %f seconds\n", backoffSec)
|
||||
time.Sleep(time.Duration(backoffSec) * baseDelay)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to upload place: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user