Skip to content

Commit c0f913c

Browse files
committed
Feat : Added basic task : supabase load fail except
1 parent 9575879 commit c0f913c

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

upstock-sentiment.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
supabase_key = os.getenv('SupaBase_Key')
3535

3636
# connect sb sdk
37-
supabase: Client = create_client(supabase_url, supabase_key)
37+
supabase: Client = create_client(
38+
supabase_url,
39+
supabase_key,
40+
options={'timeout':15} # 15sec timeoutexcept
41+
)
3842

3943
# supabase storage
4044
def download_model_file():
@@ -50,20 +54,30 @@ def download_model_file():
5054
bucket = supabase.storage.from_(bucket_name)
5155

5256
for file_path in file_paths:
53-
try:
54-
res = bucket.download(file_path)
55-
56-
# download() result bytes > res 사용, result response > res.read()실행
57-
content = res.read() if hasattr(res, "read") else res
58-
local_path = os.path.join("SaveModel", os.path.basename(file_path))
59-
60-
with open(local_path, "wb") as f:
61-
f.write(content)
62-
63-
print(f"{file_path} download complete {local_path}")
64-
65-
except Exception as e:
66-
print(f"{file_path} download fail : {e}")
57+
58+
retries = 3 # 2 time retry
59+
60+
for attempt in range(retries):
61+
try:
62+
res = bucket.download(file_path)
63+
64+
# download() result bytes > res 사용, result response > res.read()실행
65+
content = res.read() if hasattr(res, "read") else res
66+
local_path = os.path.join("SaveModel", os.path.basename(file_path))
67+
68+
with open(local_path, "wb") as f:
69+
f.write(content)
70+
71+
print(f"{file_path} download complete {local_path}")
72+
break
73+
74+
except Exception as e:
75+
print(f"{file_path} download fail : {e}")
76+
if attempt < retries -1:
77+
print('retry')
78+
time.sleep(3)
79+
else:
80+
print('error')
6781

6882
# download_model_file()
6983

@@ -302,7 +316,7 @@ def load_pickle(path, description):
302316
callbacks=[early_stop, tensorboard]
303317
)
304318

305-
model.summary()
319+
# model.summary()
306320

307321
# save
308322
try:

0 commit comments

Comments
 (0)