RetryPolicy¶
from cascaqit import RetryPolicy
RetryPolicy ¶
RetryPolicy(
max_attempts: int = 1,
timeout_seconds: float | None = None,
backoff_strategy: RetryBackoffStrategy = "none",
backoff_seconds: float = 0.0,
max_backoff_seconds: float | None = None,
retryable_error_codes: tuple[str, ...] = (),
non_retryable_error_codes: tuple[str, ...] = (),
schema_version: str = SCHEMA_VERSION,
)
Configure attempt limits, backoff and error-code rules for persistent local jobs via LocalBackend(store=...).run(retry=...). max_attempts includes the first attempt; the default of 1 means no retries. Constructing a policy does not run a job.
backoff_strategy accepts none, fixed or exponential. backoff_seconds must be nonnegative; max_backoff_seconds optionally caps the delay and cannot be smaller than the base delay. retryable_error_codes and non_retryable_error_codes cannot overlap. Unlisted codes retain the exception’s retryability flag.
timeout_seconds accepts a positive timeout declaration, but the current persistent local runners do not consume this field. It does not interrupt an overlong computation and must not be treated as a local execution deadline.
from cascaqit import RetryPolicy
policy = RetryPolicy(max_attempts=4, backoff_strategy="exponential",
backoff_seconds=0.5, max_backoff_seconds=1.0,
retryable_error_codes=("TEMPORARY",))
assert [policy.attempt_backoff_seconds(i) for i in range(1, 5)] == [0, 0.5, 1, 1]
assert policy.is_retryable_code("TEMPORARY") is True
assert policy.is_retryable_code("OTHER") is None
assert RetryPolicy.from_json(policy.to_json()) == policy
Return a delay in seconds for a one-based attempt index without sleeping. The first attempt and the none strategy return 0. Fixed uses the base delay; exponential starts with the base delay on attempt 2 and doubles thereafter, subject to the cap. Invalid nonpositive or noninteger indices raise.
Return False for a denied code, True for an allowed code and None when no override applies. None does not mean retries are forbidden.
Restore RetryPolicy from a dictionary. Restore backoff settings and error-code lists, validating the parameters again. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning RetryPolicy. Invalid JSON raises a parsing error; a non-object root raises TypeError.
Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.
Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.
Return the SHA-256 hex digest of canonical JSON. Fields, identifiers and metadata can affect it. Use it to compare saved content, not to decide physical equivalence.