Merge branch 'benny/log-sync' into public-main

This commit is contained in:
bennykok 2024-09-17 14:27:59 -07:00
commit 086d642360

View File

@ -972,6 +972,7 @@ async def send_json_override(self, event, data, sid=None):
"data": data "data": data
}) })
asyncio.create_task(update_run_ws_event(prompt_id, event, data))
# event_emitter.emit("send_json", { # event_emitter.emit("send_json", {
# "event": event, # "event": event,
# "data": data # "data": data
@ -1095,6 +1096,26 @@ async def update_run_live_status(prompt_id, live_status, calculated_progress: fl
# requests.post(status_endpoint, json=body) # requests.post(status_endpoint, json=body)
await async_request_with_retry('POST', status_endpoint, token=token, json=body) await async_request_with_retry('POST', status_endpoint, token=token, json=body)
async def update_run_ws_event(prompt_id: str, event: str, data: dict):
if prompt_id not in prompt_metadata:
return
# print("update_run_ws_event", prompt_id, event, data)
status_endpoint = prompt_metadata[prompt_id].status_endpoint
if status_endpoint is None:
return
token = prompt_metadata[prompt_id].token
body = {
"run_id": prompt_id,
"ws_event": {
"event": event,
"data": data,
},
}
await async_request_with_retry('POST', status_endpoint, token=token, json=body)
async def update_run(prompt_id: str, status: Status): async def update_run(prompt_id: str, status: Status):
global last_read_line_number global last_read_line_number
@ -1370,14 +1391,10 @@ async def handle_upload(prompt_id: str, data, key: str, content_type_key: str, d
# Upload files in the background # Upload files in the background
async def upload_in_background(prompt_id: str, data, node_id=None, have_upload=True, node_meta=None): async def upload_in_background(prompt_id: str, data, node_id=None, have_upload=True, node_meta=None):
try: try:
upload_tasks = [ await handle_upload(prompt_id, data, 'images', "content_type", "image/png")
handle_upload(prompt_id, data, 'images', "content_type", "image/png"), await handle_upload(prompt_id, data, 'files', "content_type", "image/png")
handle_upload(prompt_id, data, 'files', "content_type", "image/png"), await handle_upload(prompt_id, data, 'gifs', "format", "image/gif")
handle_upload(prompt_id, data, 'gifs', "format", "image/gif"), await handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
]
await asyncio.gather(*upload_tasks)
status_endpoint = prompt_metadata[prompt_id].status_endpoint status_endpoint = prompt_metadata[prompt_id].status_endpoint
token = prompt_metadata[prompt_id].token token = prompt_metadata[prompt_id].token
@ -1422,7 +1439,8 @@ async def update_run_with_output(prompt_id, data, node_id=None, node_meta=None):
if have_upload_media: if have_upload_media:
await update_file_status(prompt_id, data, True, node_id=node_id) await update_file_status(prompt_id, data, True, node_id=node_id)
asyncio.create_task(upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload_media, node_meta=node_meta)) # asyncio.create_task(upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload_media, node_meta=node_meta))
await upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload_media, node_meta=node_meta)
# await upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload) # await upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload)
except Exception as e: except Exception as e: