Hyrex provides automatic retry mechanisms for tasks that fail due to transient errors. Configure retries using max_retries and retry_backoff parameters.
Use on_error callbacks to monitor failures without affecting retry behavior:
from hyrex import get_hyrex_contextdef handle_error(error: Exception): context = get_hyrex_context() if context: # Log error with context print(f"Task {context.task_name} failed on attempt {context.attempt_number}: {error}") # Alert on final retry if context.attempt_number == context.max_retries: send_alert(f"Task {context.task_name} failed after {context.max_retries} attempts")@hy.task( max_retries=3, on_error=handle_error)def monitored_task(data: dict): # Task logic that might fail process_data(data)
The on_error handler must accept either no arguments or exactly one Exception argument. The handler runs after each failure but doesn’t prevent retries.