ahi-core¶
Cross-cutting helpers shared across the AHI stack. Deliberately dependency-light
so anything can depend on it. ahi-aws builds its polling on top of it.
uv add ahi-core
poll_until¶
A generic "submit then wait for a terminal state" loop with exponential backoff and an injectable clock, so it's trivial to unit-test. This is the shared engine behind both AWS clients.
from ahi.core import poll_until
execution = poll_until(
lambda: client.get_query_execution(QueryExecutionId=qid),
lambda e: e["QueryExecution"]["Status"]["State"] in {"SUCCEEDED", "FAILED"},
timeout=300, # seconds before PollTimeoutError
interval=1.0, # initial delay
backoff=1.5, # growth factor
max_interval=30.0, # cap on the delay
)
The first fetch happens before any sleep, so an already-terminal call returns
immediately. On timeout it raises PollTimeoutError.
get_logger¶
A namespaced logger under ahi.* with a NullHandler attached, so libraries
never configure global logging or emit "no handlers" warnings. The application
owns handler/level configuration.
from ahi.core import get_logger
log = get_logger("aws.redshift") # -> logging.getLogger("ahi.aws.redshift")
log.debug("submitted statement %s", statement_id)
Errors¶
AhiError is the base of everything the AHI stack raises — catch it to handle
any of our errors generically. PollTimeoutError (also a TimeoutError) is
raised by poll_until.
from ahi.core import AhiError, PollTimeoutError