Task State Manager#

class ccat_data_transfer.task_state_manager.TaskStateManager(redis_client)[source]#

Bases: object

Manager for tracking and recovering task states across all operation types.

__init__(redis_client)[source]#
register_task(task_id, operation_type, operation_id, additional_info=None, max_retries=3)[source]#

Register a task in Redis with its metadata.

Parameters:
  • task_id (str) – Celery task ID

  • operation_type (str) – Type of operation (transfer, archive, package, delete, verify)

  • operation_id (int) – Database ID of the operation

  • additional_info (dict, optional) – Additional context about the operation

  • max_retries (int, optional) – Maximum retry count for this task

update_heartbeat(task_id)[source]#

Update task heartbeat to indicate it’s still running.

complete_task(task_id)[source]#

Mark task as completed and remove from tracking.

fail_task(task_id, error_message, is_retryable=True)[source]#

Mark task as failed.

Returns:

(can_retry, operation_type, operation_id)

Return type:

tuple

get_stalled_tasks(heartbeat_timeout=300)[source]#

Find tasks that haven’t updated their heartbeat recently.

Returns:

List of dicts with task information

Return type:

list

Overview#

The Task State Manager manages task state transitions and persistence.

Key Functions#

  • update_task_state() - Update task state

  • get_task_state() - Get current task state