Skip to content

Commit

Permalink
fix for file_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed May 10, 2024
1 parent d22a514 commit 5e48808
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions bussilab/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,28 @@ def notify(message: str = "",
ts=response["files"][0]["shares"][k][channel][0]["ts"]
else:
file_id=response["files"][0]["id"]
for i in range(10):
max_attempts=10
num_attempts=0
num_attempts_delay=5
while True:
num_attempts+=1
response = _try_multiple_times(client.files_info, file=file_id)
if len(list(response["file"]["shares"].keys()))>0:
k=list(response["file"]["shares"].keys())[0] # empirically, pick the first one. There should be only one!
channel=list(response["file"]["shares"][k].keys())[0] # empirically, pick the first one. There should be only one!
ts=response["file"]["shares"][k][channel][0]["ts"]
time.sleep(1)
break
warnings.warn("Slack API, missing shares for file ID " + file_id +", retrying " + str(i))
response = _try_multiple_times(client.files_info, file=file_id)


if num_attempts>=max_attempts:
raise RuntimeError("Cannot obtain shares info for file ID "+str(file_id))
wait=1.0
if num_attempts>num_attempts_delay:
wait=2**(num_attempts-num_attempts_delay)
warnings.warn("Slack API, missing shares for file ID " + file_id +", retry after "
+str(wait)
+" seconds"+
" ["+str(num_attempts)+"/"+str(max_attempts)+"]",
UserWarning)
time.sleep(wait)
else:
if reply:
response = _try_multiple_times(client.files_upload,
Expand Down

0 comments on commit 5e48808

Please sign in to comment.