Skip to content

Commit

Permalink
Add status
Browse files Browse the repository at this point in the history
  • Loading branch information
yoland68 committed Jul 12, 2024
1 parent 2f4ad36 commit 1718b3c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
import os
import re
import subprocess
from enum import Enum

import requests
from google.cloud import storage


# Reference: https://github.com/Comfy-Org/registry-backend/blob/main/openapi.yml#L2031
class WfRunStatus(Enum):
Started = "WorkflowRunStatusStarted"
Failed = "WorkflowRunStatusFailed"
Completed = "WorkflowRunStatusCompleted"


def read_json_file(file_path):
with open(file_path, "r", encoding="utf-8") as file:
return json.load(file)
Expand Down Expand Up @@ -57,7 +65,12 @@ def upload_to_gcs(bucket_name: str, destination_blob_name: str, source_file_name


def send_payload_to_api(
args, output_files_gcs_paths, workflow_name, start_time, end_time
args,
output_files_gcs_paths,
workflow_name,
start_time,
end_time,
status=WfRunStatus.Completed,
):

is_pr = args.branch_name.endswith("/merge")
Expand All @@ -76,7 +89,7 @@ def send_payload_to_api(
"bucket_name": args.gsc_bucket_name,
"output_files_gcs_paths": output_files_gcs_paths,
# TODO: support comfy logs
# "comfy_logs_gcs_path":
# "comfy_logs_gcs_path":
"commit_hash": args.commit_hash,
"commit_time": args.commit_time,
"commit_message": args.commit_message,
Expand All @@ -94,7 +107,7 @@ def send_payload_to_api(
"comfy_run_flags": args.comfy_run_flags,
"python_version": args.python_version,
"torch_version": args.torch_version,
# "status": "WorkflowRunStatusStarted"
"status": status,
}

# Convert payload dictionary to a JSON string
Expand Down Expand Up @@ -130,6 +143,7 @@ def main(args):
counter = 1

for workflow_file_name in workflow_files:
send_payload_to_api(args, "", workflow_file_name, 0, 0, WfRunStatus.Started)
# Construct the file path
file_path = f"workflows/{workflow_file_name}"
print(f"Running workflow {file_path}")
Expand All @@ -145,6 +159,14 @@ def main(args):
)
print("Output:", result.stdout)
except subprocess.CalledProcessError as e:
send_payload_to_api(
args,
"",
workflow_file_name,
start_time,
int(datetime.datetime.now().timestamp()),
WfRunStatus.Failed,
)
print("Error STD Out:", e.stdout)
print("Error:", e.stderr)
raise e
Expand All @@ -160,7 +182,14 @@ def main(args):
f"{args.workspace_path}/output/{args.output_file_prefix}_{counter:05}_.png",
)

send_payload_to_api(args, gs_path, workflow_file_name, start_time, end_time)
send_payload_to_api(
args,
gs_path,
workflow_file_name,
start_time,
end_time,
WfRunStatus.Completed,
)
counter += 1


Expand Down

0 comments on commit 1718b3c

Please sign in to comment.