Read big boards within the agents' reach: countries and remote from the enabled agents, Europe for favourites, filtered at the source by six hosts
app/jobs/reach.py derives each board's reach once per pull and the pull hands it to the runner through the batch payload. SmartRecruiters, Eightfold and SuccessFactors filter one country a request, Phenom a list, Workday and Oracle by host ids from facets. Remote beside countries is a series of its own, since two facets intersect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3adafd8950
commit
3462a4abe7
17 files changed
+1324
-116
No files matched your search
+65
-19
@@ -289,14 +289,22 @@ def resolve_key(key: Key, keys: Mapping[str, Any] | None) -> dict[str, str]:
|
||||
return out
|
||||
|
||||
|
||||
#: The most series a reach may cost on a `one` filter: a reach of more
|
||||
#: countries (a favourite's Europe) reads such a host unfiltered instead.
|
||||
MAX_SERIES = 8
|
||||
|
||||
|
||||
def ask_for(module: ModuleType, subscription_params: Mapping[str, Any] | None = None,
|
||||
reach: Mapping[str, Any] | None = None, *,
|
||||
keys: Mapping[str, Any] | None = None) -> Ask:
|
||||
"""The `Ask` one target resolves to. `reach` (from the agents, package F)
|
||||
and then the subscription's own `params` (a board's override, e.g.
|
||||
`{"countries": ["DK"], "remote": true}`, or a search's saved params) set
|
||||
the dimensions, params winning per dimension, narrowed to the ones the
|
||||
reader declares in `READS.filters`. A search's params go whole into
|
||||
"""The `Ask` one target resolves to. `reach` (from the agents, see
|
||||
`app/jobs/reach.py`) and then the subscription's own `params` (a board's
|
||||
override, e.g. `{"countries": ["DK"], "remote": true}`, or a search's
|
||||
saved params) set the dimensions, params winning per dimension, narrowed
|
||||
to the ones the reader declares in `READS.filters`. `{"reach": "all"}` in
|
||||
the params drops the reach, and so does a reach of more than
|
||||
`MAX_SERIES` countries on a reader whose country filter is `one`. A
|
||||
`remote` of False asks nothing. A search's params go whole into
|
||||
`Ask.params`; a reader with `READS.key` gets the resolved key under
|
||||
`Ask.params["key"]` (see `resolve_key`, which raises when it is missing).
|
||||
A module without `READS` gets `Ask()`."""
|
||||
@@ -304,7 +312,12 @@ def ask_for(module: ModuleType, subscription_params: Mapping[str, Any] | None =
|
||||
return Ask()
|
||||
reads: Reads = module.READS
|
||||
params = dict(subscription_params or {})
|
||||
wanted = _dimensions(module, reach or {}) | _dimensions(module, params)
|
||||
reached = {} if params.get("reach") == "all" else _dimensions(module, reach or {})
|
||||
if reads.filters.country == "one" and len(reached.get("country", ())) > MAX_SERIES:
|
||||
reached = {}
|
||||
wanted = reached | _dimensions(module, params)
|
||||
if wanted.get("remote") is False:
|
||||
del wanted["remote"]
|
||||
fields: dict[str, Any] = {_ASK_FIELD[name]: value for name, value in wanted.items()
|
||||
if name in reads.filters.declared()}
|
||||
extra: dict[str, Any] = dict(params) if reads.scope == "search" else {}
|
||||
@@ -320,29 +333,61 @@ def filtered(ask: Ask) -> bool:
|
||||
|
||||
def series(module: ModuleType, ask: Ask,
|
||||
facets: Mapping[str, Mapping[str, str]] | None = None) -> list[Ask]:
|
||||
"""The series of requests `ask` takes on this reader: one per value of a
|
||||
dimension declared `one` (the product when two are), one with every
|
||||
value for `many`, and host ids from `facets` for `ids` (values `facets`
|
||||
does not know are dropped; an empty list when none is left, since the
|
||||
host then has nothing in reach). `[ask]` for a module without `READS`."""
|
||||
"""The series of requests `ask` takes on this reader. Remote with a
|
||||
country or a place is two parts, "in these places, or remote": the
|
||||
places without remote, and remote alone. Each part is one series per
|
||||
value of a dimension declared `one` (the product when two are), one
|
||||
with every value for `many`, and host ids from `facets` for `ids`:
|
||||
values `facets` does not know are dropped, and a part with none left is
|
||||
no series, since the host has nothing of it; a dimension `facets` does
|
||||
not state at all is read unfiltered, and so is remote alone, while the
|
||||
remote part beside places is then left out. `[ask]` for a module
|
||||
without `READS`."""
|
||||
if not declared(module):
|
||||
return [ask]
|
||||
if ask.remote and (ask.countries or ask.places):
|
||||
return [*_series(module, ask.model_copy(update={"remote": None}), facets),
|
||||
*_series(module, ask.model_copy(update={"countries": (), "places": ()}),
|
||||
facets, beside=True)]
|
||||
return _series(module, ask, facets)
|
||||
|
||||
|
||||
def _series(module: ModuleType, ask: Ask, facets: Mapping[str, Mapping[str, str]] | None,
|
||||
beside: bool = False) -> list[Ask]:
|
||||
"""`series` for an ask that is places or remote, not both. `beside` marks
|
||||
the remote part of an ask that also has places."""
|
||||
reach = module.READS.filters
|
||||
known_facets = facets or {}
|
||||
countries, places = ask.countries, ask.places
|
||||
for dimension in ("country", "place"):
|
||||
values = countries if dimension == "country" else places
|
||||
if getattr(reach, dimension) != "ids" or not values:
|
||||
continue
|
||||
known = (facets or {}).get(dimension) or {}
|
||||
mapped = tuple(known[v] for v in values if v in known)
|
||||
if not mapped:
|
||||
log.info("readers: %s knows none of %s %s", module.NAME, dimension,
|
||||
", ".join(values))
|
||||
return []
|
||||
if dimension not in known_facets:
|
||||
log.info("readers: %s states no %s facet; read unfiltered", module.NAME, dimension)
|
||||
mapped: tuple[str, ...] = ()
|
||||
else:
|
||||
known = known_facets.get(dimension) or {}
|
||||
mapped = tuple(dict.fromkeys(known[v] for v in values if v in known))
|
||||
if not mapped:
|
||||
log.info("readers: %s knows none of %s %s", module.NAME, dimension,
|
||||
", ".join(values))
|
||||
return []
|
||||
if dimension == "country":
|
||||
countries = mapped
|
||||
else:
|
||||
places = mapped
|
||||
if reach.remote == "ids" and ask.remote:
|
||||
if "remote" not in known_facets:
|
||||
if beside:
|
||||
log.info("readers: %s states no remote facet; remote left out", module.NAME)
|
||||
return []
|
||||
ask = ask.model_copy(update={"remote": None})
|
||||
else:
|
||||
ids = tuple(dict.fromkeys((known_facets.get("remote") or {}).values()))
|
||||
if not ids:
|
||||
return []
|
||||
ask = ask.model_copy(update={"remote_ids": ids})
|
||||
by_country = [(c,) for c in countries] if reach.country == "one" and countries \
|
||||
else [countries]
|
||||
by_place = [(p,) for p in places] if reach.place == "one" and places else [places]
|
||||
@@ -505,12 +550,13 @@ def _load(state: Mapping[str, str], key: str) -> dict[str, Any]:
|
||||
|
||||
def facets_for(module: ModuleType, slug: str, get: Get, ask: Ask,
|
||||
state: MutableMapping[str, str] | None = None, key: str = "") -> dict[str, Any]:
|
||||
"""The reader's `facets` when `ask` sets a dimension it declares `ids`,
|
||||
"""The reader's `facets` when `ask` sets a dimension it declares `ids`
|
||||
(a country, a place, or remote),
|
||||
kept in `state[key]` for `FACETS_TTL`; `{}` otherwise."""
|
||||
if not declared(module) or not hasattr(module, "facets"):
|
||||
return {}
|
||||
ids = [name for name, reach in module.READS.filters.declared().items() if reach == "ids"]
|
||||
if not any(getattr(ask, _ASK_FIELD[name]) for name in ids if name in ("country", "place")):
|
||||
if not any(getattr(ask, _ASK_FIELD[name]) for name in ids if name != "query"):
|
||||
return {}
|
||||
now = datetime.now(UTC)
|
||||
if state is not None and key:
|
||||
|
||||
Reference in new issue
Block a user