PERF 重定向日志到S3

This commit is contained in:
kyj@bowong.ai 2025-03-24 17:33:08 +08:00
parent e390b015ec
commit c0ae96622f
3 changed files with 9 additions and 7 deletions

View File

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.9 (pythonProject)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="ComfyUI" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="ComfyUI-3.10" project-jdk-type="Python SDK" />
</project>

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="ComfyUI" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="ComfyUI-3.10" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -52,10 +52,10 @@ image = (
.run_commands("comfy node install https://github.com/rgthree/rgthree-comfy")
.run_commands("comfy node install https://github.com/cubiq/ComfyUI_essentials")
.run_commands("comfy node install https://github.com/melMass/comfy_mtb")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI_SparkTTS.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/cosyvoice_comfyui.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-LatentSync-Node.git")
.run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git")
.run_commands(
"mkdir -p /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model && rm -rf /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model && ln -s /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model"
).run_commands(
@ -120,13 +120,15 @@ class ComfyUI:
@modal.enter()
def launch_comfy_background(self):
# starts the ComfyUI server in the background exactly once when the first input is received
self.session_id = str(uuid.uuid4())
cmd = "echo client_uuid: {}&&rm -rf /root/comfy/ComfyUI/user&&mkdir -p /root/comfy/ComfyUI/output_s3/logs/{}&&ln -s /root/comfy/ComfyUI/output_s3/logs/{} /root/comfy/ComfyUI/user".format(self.session_id,self.session_id, self.session_id)
subprocess.run(cmd, shell=True, check=True)
cmd = "comfy launch --background"
subprocess.run(cmd, shell=True, check=True)
@modal.method()
def infer(self, workflow_json: str = ""):
# runs the comfy run --workflow command as a subprocess
session_id = str(uuid.uuid4())
workflow = json.loads(workflow_json)
for node in workflow.values():
if node.get("class_type") == "ComfyUIDeployExternalText":
@ -136,9 +138,9 @@ class ComfyUI:
os.makedirs(os.path.dirname(file_to_move.replace("input_s3", "input")), exist_ok=True)
shutil.copy(file_to_move, file_to_move.replace("input_s3", "input"))
node["inputs"]["default_value"] = node["inputs"]["default_value"].replace("input_s3", "input")
with open(f"/root/{session_id}.json", "w", encoding="utf-8") as f:
with open(f"/root/{self.session_id}.json", "w", encoding="utf-8") as f:
f.write(json.dumps(workflow, ensure_ascii=False))
cmd = f"comfy run --workflow /root/{session_id}.json --wait --timeout 900 --verbose"
cmd = f"comfy run --workflow /root/{self.session_id}.json --wait --timeout 900 --verbose"
subprocess.run(cmd, shell=True, check=True)
# looks up the name of the output image file based on the workflow
@ -160,7 +162,7 @@ class ComfyUI:
shutil.copy(os.path.join(output_dir, f), os.path.join(output_dir.replace("output", "output_s3"), f))
return f
@modal.web_endpoint(method="POST")
@modal.fastapi_endpoint(method="POST")
def api(self, item: Dict):
from fastapi import Response