Skip to content

Commit

Permalink
Improve error handling and increase waiting preriod
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Dec 5, 2023
1 parent c0e8ff1 commit a1fb5fc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sam/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def process_run(event: {str, Any}, say: Say):
msg = say(f":speech_balloon:", mrkdwn=True)
logger.info(f"User={user_id} started Run={run.id} for Thread={thread_id}")
for i in itertools.count():
if run.status not in ["queued", "in_progress"] or i > 10:
if run.status not in ["queued", "in_progress"] or i > 16:
break
run = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
time.sleep(min(2**i, 10))
if run.status != "completed":
if run.status == "failed":
logger.error(run.last_error)
say.client.chat_update(
channel=say.channel,
Expand All @@ -88,6 +88,15 @@ def process_run(event: {str, Any}, say: Say):
logger.error(f"Run {run.id} {run.status} for Thread {thread_id}")
logger.error(run.last_error.message)
return
elif run.status != "completed":
logger.error(f"Run {run.id} {run.status} for Thread {thread_id}")
say.client.chat_update(
channel=say.channel,
ts=msg["ts"],
text=f"🤯",
mrkdwn=True,
)
return
logger.info(f"Run={run.id} {run.status} for Thread={thread_id}")

messages = client.beta.threads.messages.list(thread_id=thread_id)
Expand Down

0 comments on commit a1fb5fc

Please sign in to comment.