Skip to content

Commit

Permalink
feat: add retry to queue workflows
Browse files Browse the repository at this point in the history
(cherry picked from commit f0f14df)
  • Loading branch information
Calvin-Huang committed Dec 2, 2024
1 parent f4bf6b0 commit dfb856b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/rp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,17 @@ def queue_workflow(workflow):
# The top level element "prompt" is required by ComfyUI
data = json.dumps({"prompt": workflow}).encode("utf-8")

req = urllib.request.Request(f"http://{COMFY_HOST}/prompt", data=data)
return json.loads(urllib.request.urlopen(req).read())
retries = 0
while retries < COMFY_API_AVAILABLE_MAX_RETRIES:
try:
req = urllib.request.Request(f"http://{COMFY_HOST}/prompt", data=data)
return json.loads(urllib.request.urlopen(req).read())
except Exception as e:
print(f"Error queuing workflow: {str(e)}. Retrying...")
time.sleep(COMFY_API_AVAILABLE_INTERVAL_MS / 1000)
retries += 1

raise Exception("Max retries reached while queuing workflow")


def get_history(prompt_id):
Expand Down

0 comments on commit dfb856b

Please sign in to comment.