diff --git a/crawler/frontend/src/components/TaskIndicator.tsx b/crawler/frontend/src/components/TaskIndicator.tsx index 403692c..4ca1fa0 100644 --- a/crawler/frontend/src/components/TaskIndicator.tsx +++ b/crawler/frontend/src/components/TaskIndicator.tsx @@ -16,6 +16,8 @@ interface TaskIndicatorProps { export function TaskIndicator({ taskID, onTaskCancelled }: TaskIndicatorProps) { const [user, setUser] = useState(null); const [progressPercentage, setProgressPercentage] = useState(0); + const [processed, setProcessed] = useState(null); + const [total, setTotal] = useState(null); const [taskStatus, setTaskStatus] = useState(null); const [isCancelling, setIsCancelling] = useState(false); @@ -32,6 +34,8 @@ export function TaskIndicator({ taskID, onTaskCancelled }: TaskIndicatorProps) { // Reset state for new task setTaskStatus(TaskStatus.PENDING); setProgressPercentage(0); + setProcessed(null); + setTotal(null); const pollTaskStatus = async () => { try { @@ -53,6 +57,12 @@ export function TaskIndicator({ taskID, onTaskCancelled }: TaskIndicatorProps) { try { const parsedResult: TaskResult = JSON.parse(data.result); setProgressPercentage(parsedResult.progress * 100); + if (parsedResult.processed !== undefined) { + setProcessed(parsedResult.processed); + } + if (parsedResult.total !== undefined) { + setTotal(parsedResult.total); + } } catch { // Ignore parsing errors } @@ -112,8 +122,18 @@ export function TaskIndicator({ taskID, onTaskCancelled }: TaskIndicatorProps) { return ; }; + const getProgressText = () => { + if (processed !== null && total !== null && total > 0) { + return `${processed} / ${total}`; + } + return `${Math.round(progressPercentage)}%`; + }; + const getTooltipContent = () => { if (isInProgress) { + if (processed !== null && total !== null && total > 0) { + return `Processing: ${processed} / ${total} listings (${Math.round(progressPercentage)}%)`; + } return `Task running: ${Math.round(progressPercentage)}%`; } if (taskStatus === TaskStatus.SUCCESS) { @@ -133,7 +153,7 @@ export function TaskIndicator({ taskID, onTaskCancelled }: TaskIndicatorProps) {
{getStatusIcon()} - {isInProgress ? `${Math.round(progressPercentage)}%` : taskStatus} + {isInProgress ? getProgressText() : taskStatus}
diff --git a/crawler/frontend/src/types/index.ts b/crawler/frontend/src/types/index.ts index f538af3..5d3d931 100644 --- a/crawler/frontend/src/types/index.ts +++ b/crawler/frontend/src/types/index.ts @@ -53,6 +53,8 @@ export interface TaskStatusResponse { export interface TaskResult { progress: number; + processed?: number; + total?: number; } export interface RefreshListingsResponse { diff --git a/crawler/tasks/listing_tasks.py b/crawler/tasks/listing_tasks.py index 33afe45..3233947 100644 --- a/crawler/tasks/listing_tasks.py +++ b/crawler/tasks/listing_tasks.py @@ -84,7 +84,7 @@ async def dump_listings_and_monitor( ) task.update_state( state=f"Progress: {progress_ratio * 100}% ({progress} out of {len(missing_ids)})", - meta={"progress": progress_ratio}, + meta={"progress": progress_ratio, "processed": progress, "total": len(missing_ids)}, ) await asyncio.sleep(1)