Skip to content

Commit dade454

Browse files
committed
Fix publish script
Signed-off-by: Andy Doan <[email protected]>
1 parent eb3ac24 commit dade454

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

.github/workflows/publish_artifacts.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from multiprocessing import Pool
66
import os
77
import sys
8+
from time import sleep
89
from typing import List
910

1011
import requests
@@ -19,17 +20,45 @@ def upload_file(args):
1920
headers = {
2021
"Authentication": f"Bearer {gh_token}",
2122
}
22-
r = requests.put(url, headers=headers, allow_redirects=False)
23-
if not r.ok:
24-
return name, f"Unable to get signed url HTTP_{r.status_code} - {r.text}"
23+
24+
# Fibonacci backoff
25+
for x in (1, 2, 3, 5, 0):
26+
r = requests.put(url, headers=headers, allow_redirects=False)
27+
if not r.ok:
28+
if not x:
29+
return (
30+
name,
31+
f"Unable to get signed url HTTP_{r.status_code} - {r.text}",
32+
)
33+
else:
34+
print(
35+
f"Error getting signed URL for {name}: {r.status_code} - {r.text}",
36+
flush=True,
37+
)
38+
print(f"Retrying in {x} seconds")
39+
sleep(x)
2540

2641
url = r.headers["location"]
2742
path = os.path.join(base, name)
28-
r = requests.put(
29-
url, data=open(path, "rb"), headers={"Content-type": "application/octet-stream"}
30-
)
31-
if not r.ok:
32-
return name, f"Unable to upload content HTTP_{r.status_code} - {r.text}"
43+
# Fibonacci backoff
44+
for x in (1, 2, 3, 0):
45+
r = requests.put(
46+
url,
47+
data=open(path, "rb"),
48+
headers={"Content-type": "application/octet-stream"},
49+
)
50+
if not r.ok:
51+
if not x:
52+
return (
53+
name,
54+
f"Unable to upload content HTTP_{r.status_code} - {r.text}",
55+
)
56+
else:
57+
print(
58+
f"Unable to upload content for {name}: HTTP_{r.status_code} - {r.text}"
59+
)
60+
print(f"Retrying in {x} seconds")
61+
sleep(x)
3362

3463
return name, None
3564
except Exception as e:

0 commit comments

Comments
 (0)