generated from coulomb/repo-seed
Add State Hub RecentlyOnScope invocation
This commit is contained in:
@@ -102,7 +102,8 @@ async def resolve_context(
|
||||
Returns: {bind_key: resolved_value, ...}
|
||||
|
||||
Source types are dispatched via CONTEXT_RESOLVER_REGISTRY.
|
||||
A resolver that raises logs a warning and binds {} — it does not abort the run.
|
||||
A resolver that raises logs a warning and binds {} unless the context source
|
||||
is marked required, in which case the activity fails visibly.
|
||||
The 'static' type is handled inline without a registry entry.
|
||||
"""
|
||||
import activity_core.context_resolvers # noqa: F401 — registers all adapters
|
||||
@@ -113,6 +114,7 @@ async def resolve_context(
|
||||
source_type = source.get("type", "")
|
||||
query = source.get("query", "")
|
||||
params = source.get("params") or {}
|
||||
required = bool(source.get("required") or params.get("required", False))
|
||||
raw_bind = source.get("bind_to") or source.get("name") or source_type
|
||||
# Strip the 'context.' namespace prefix so evaluator can find the key.
|
||||
bind_key = raw_bind.removeprefix("context.") if raw_bind.startswith("context.") else raw_bind
|
||||
@@ -123,6 +125,11 @@ async def resolve_context(
|
||||
|
||||
resolver_cls = CONTEXT_RESOLVER_REGISTRY.get(source_type)
|
||||
if resolver_cls is None:
|
||||
if required:
|
||||
raise ApplicationError(
|
||||
f"Required context source type {source_type!r} is not registered",
|
||||
non_retryable=True,
|
||||
)
|
||||
activity.logger.warning(
|
||||
"Unknown context source type %r — binding {}",
|
||||
source_type,
|
||||
@@ -133,6 +140,10 @@ async def resolve_context(
|
||||
try:
|
||||
snapshot[bind_key] = resolver_cls().resolve(query, None, params)
|
||||
except Exception as exc:
|
||||
if required:
|
||||
raise ApplicationError(
|
||||
f"Required context resolver {source_type!r}/{query!r} failed: {exc}"
|
||||
) from exc
|
||||
activity.logger.warning(
|
||||
"Context resolver %r failed — %s; binding {}",
|
||||
source_type,
|
||||
|
||||
Reference in New Issue
Block a user