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