mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-12-19 19:13:02 +08:00
filter by workflow id and remove null fields
This commit is contained in:
parent
460b848669
commit
1f7c1a954e
@ -3,6 +3,8 @@ Job utilities for the /api/jobs endpoint.
|
|||||||
Provides normalization and helper functions for job status tracking.
|
Provides normalization and helper functions for job status tracking.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from comfy_api.internal import prune_dict
|
||||||
|
|
||||||
|
|
||||||
class JobStatus:
|
class JobStatus:
|
||||||
"""Job status constants."""
|
"""Job status constants."""
|
||||||
@ -54,18 +56,14 @@ def normalize_queue_item(item, status):
|
|||||||
extra_pnginfo = extra_data.get('extra_pnginfo') or {}
|
extra_pnginfo = extra_data.get('extra_pnginfo') or {}
|
||||||
workflow_id = extra_pnginfo.get('workflow', {}).get('id')
|
workflow_id = extra_pnginfo.get('workflow', {}).get('id')
|
||||||
|
|
||||||
return {
|
return prune_dict({
|
||||||
'id': prompt_id,
|
'id': prompt_id,
|
||||||
'status': status,
|
'status': status,
|
||||||
'priority': priority,
|
'priority': priority,
|
||||||
'create_time': create_time,
|
'create_time': create_time,
|
||||||
'execution_error': None,
|
|
||||||
'execution_start_time': None,
|
|
||||||
'execution_end_time': None,
|
|
||||||
'outputs_count': 0,
|
'outputs_count': 0,
|
||||||
'preview_output': None,
|
|
||||||
'workflow_id': workflow_id,
|
'workflow_id': workflow_id,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
|
||||||
def normalize_history_item(prompt_id, history_item, include_outputs=False):
|
def normalize_history_item(prompt_id, history_item, include_outputs=False):
|
||||||
@ -104,18 +102,18 @@ def normalize_history_item(prompt_id, history_item, include_outputs=False):
|
|||||||
if event_name == 'execution_error':
|
if event_name == 'execution_error':
|
||||||
execution_error = event_data
|
execution_error = event_data
|
||||||
|
|
||||||
job = {
|
job = prune_dict({
|
||||||
'id': prompt_id,
|
'id': prompt_id,
|
||||||
'status': status,
|
'status': status,
|
||||||
'priority': priority,
|
'priority': priority,
|
||||||
'create_time': create_time,
|
'create_time': create_time,
|
||||||
'execution_error': execution_error,
|
|
||||||
'execution_start_time': execution_start_time,
|
'execution_start_time': execution_start_time,
|
||||||
'execution_end_time': execution_end_time,
|
'execution_end_time': execution_end_time,
|
||||||
|
'execution_error': execution_error,
|
||||||
'outputs_count': outputs_count,
|
'outputs_count': outputs_count,
|
||||||
'preview_output': preview_output,
|
'preview_output': preview_output,
|
||||||
'workflow_id': workflow_id,
|
'workflow_id': workflow_id,
|
||||||
}
|
})
|
||||||
|
|
||||||
if include_outputs:
|
if include_outputs:
|
||||||
job['outputs'] = outputs
|
job['outputs'] = outputs
|
||||||
@ -210,7 +208,7 @@ def get_job(prompt_id, running, queued, history):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_all_jobs(running, queued, history, status_filter=None, sort_by="created_at", sort_order="desc", limit=None, offset=0):
|
def get_all_jobs(running, queued, history, status_filter=None, workflow_id=None, sort_by="created_at", sort_order="desc", limit=None, offset=0):
|
||||||
"""
|
"""
|
||||||
Get all jobs (running, pending, completed) with filtering and sorting.
|
Get all jobs (running, pending, completed) with filtering and sorting.
|
||||||
|
|
||||||
@ -219,6 +217,7 @@ def get_all_jobs(running, queued, history, status_filter=None, sort_by="created_
|
|||||||
queued: List of pending queue items
|
queued: List of pending queue items
|
||||||
history: Dict of history items keyed by prompt_id
|
history: Dict of history items keyed by prompt_id
|
||||||
status_filter: List of statuses to include (from JobStatus.ALL)
|
status_filter: List of statuses to include (from JobStatus.ALL)
|
||||||
|
workflow_id: Filter by workflow ID
|
||||||
sort_by: Field to sort by ('created_at', 'execution_duration')
|
sort_by: Field to sort by ('created_at', 'execution_duration')
|
||||||
sort_order: 'asc' or 'desc'
|
sort_order: 'asc' or 'desc'
|
||||||
limit: Maximum number of items to return
|
limit: Maximum number of items to return
|
||||||
@ -248,6 +247,9 @@ def get_all_jobs(running, queued, history, status_filter=None, sort_by="created_
|
|||||||
if (is_failed and include_failed) or (not is_failed and include_completed):
|
if (is_failed and include_failed) or (not is_failed and include_completed):
|
||||||
jobs.append(normalize_history_item(prompt_id, history_item))
|
jobs.append(normalize_history_item(prompt_id, history_item))
|
||||||
|
|
||||||
|
if workflow_id:
|
||||||
|
jobs = [j for j in jobs if j.get('workflow_id') == workflow_id]
|
||||||
|
|
||||||
jobs = apply_sorting(jobs, sort_by, sort_order)
|
jobs = apply_sorting(jobs, sort_by, sort_order)
|
||||||
|
|
||||||
total_count = len(jobs)
|
total_count = len(jobs)
|
||||||
|
|||||||
@ -753,12 +753,15 @@ class PromptServer():
|
|||||||
status=400
|
status=400
|
||||||
)
|
)
|
||||||
|
|
||||||
|
workflow_id = query.get('workflow_id', None)
|
||||||
|
|
||||||
running, queued = self.prompt_queue.get_current_queue_volatile()
|
running, queued = self.prompt_queue.get_current_queue_volatile()
|
||||||
history = self.prompt_queue.get_history()
|
history = self.prompt_queue.get_history()
|
||||||
|
|
||||||
jobs, total = get_all_jobs(
|
jobs, total = get_all_jobs(
|
||||||
running, queued, history,
|
running, queued, history,
|
||||||
status_filter=status_filter,
|
status_filter=status_filter,
|
||||||
|
workflow_id=workflow_id,
|
||||||
sort_by=sort_by,
|
sort_by=sort_by,
|
||||||
sort_order=sort_order,
|
sort_order=sort_order,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
|||||||
@ -925,8 +925,6 @@ class TestExecution:
|
|||||||
assert "create_time" in job, "Job should have create_time"
|
assert "create_time" in job, "Job should have create_time"
|
||||||
assert "outputs_count" in job, "Job should have outputs_count"
|
assert "outputs_count" in job, "Job should have outputs_count"
|
||||||
assert "preview_output" in job, "Job should have preview_output"
|
assert "preview_output" in job, "Job should have preview_output"
|
||||||
assert "workflow_id" in job, "Job should have workflow_id"
|
|
||||||
assert "execution_error" in job, "Job should have execution_error"
|
|
||||||
|
|
||||||
def test_jobs_api_preview_output_structure(
|
def test_jobs_api_preview_output_structure(
|
||||||
self, client: ComfyClient, builder: GraphBuilder
|
self, client: ComfyClient, builder: GraphBuilder
|
||||||
|
|||||||
@ -256,9 +256,10 @@ class TestNormalizeQueueItem:
|
|||||||
assert job['status'] == 'pending'
|
assert job['status'] == 'pending'
|
||||||
assert job['priority'] == 10
|
assert job['priority'] == 10
|
||||||
assert job['create_time'] == 1234567890
|
assert job['create_time'] == 1234567890
|
||||||
assert job['execution_start_time'] is None
|
assert 'execution_start_time' not in job
|
||||||
assert job['execution_end_time'] is None
|
assert 'execution_end_time' not in job
|
||||||
assert job['execution_error'] is None
|
assert 'execution_error' not in job
|
||||||
|
assert 'preview_output' not in job
|
||||||
assert job['outputs_count'] == 0
|
assert job['outputs_count'] == 0
|
||||||
assert job['workflow_id'] == 'workflow-abc'
|
assert job['workflow_id'] == 'workflow-abc'
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user