Process status reader
cutana.process_status_reader
¶
Process status reader for Cutana - handles individual process progress file reading.
This module is responsible for: - Reading individual process progress files with error handling - Process details retrieval from files - Completion status detection at process level - File-based status aggregation
ProcessStatusReader(progress_dir=None, session_id=None)
¶
Handles reading individual process progress from files.
This class provides all file-reading operations for individual process progress tracking, including process details retrieval, completion detection, and file-based status aggregation.
Initialize the job status reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_dir
|
str
|
Directory for progress files (default: system temp) |
None
|
session_id
|
str
|
Session ID for progress file isolation (required for reading specific session) |
None
|
read_progress_file(process_id)
¶
Read progress data from file with error handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_id
|
str
|
Process identifier |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Progress data or None if file doesn't exist/is corrupted |
get_session_progress_files()
¶
Get all progress files for the current session.
Returns:
| Type | Description |
|---|---|
List[Path]
|
List of progress file paths for this session |
get_process_details(active_processes=None)
¶
Get detailed information about processes from progress files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_processes
|
Dict[str, Dict[str, Any]]
|
Optional dict of active process info (for fallback data) |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
Dictionary mapping process IDs to their details |
check_completion_status(total_sources=0)
¶
Check completion status by aggregating all session progress files.
This method reads all progress files for this session to get the true completion status, which may be more up-to-date than in-memory counters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_sources
|
int
|
Expected total sources (for validation) |
0
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing aggregated completion status |
get_aggregated_status(total_sources=0, completed_sources=0, failed_sources=0, start_time=None, system_resources=None)
¶
Get comprehensive status information aggregated from progress files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_sources
|
int
|
Total sources being processed (fallback) |
0
|
completed_sources
|
int
|
Completed sources count (fallback) |
0
|
failed_sources
|
int
|
Failed sources count (fallback) |
0
|
start_time
|
float
|
Job start time (fallback) |
None
|
system_resources
|
Dict[str, Any]
|
System resource information |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing complete status |
cleanup_stale_processes(timeout=1800)
¶
Identify stale processes based on their progress file timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Timeout in seconds for considering a process stale |
1800
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of process IDs that are considered stale |