Compare commits

..
2 Commits
+16 -5
View File
@@ -193,7 +193,8 @@ async def execute_monitor_logic(
proxies: AioProxies,
headers: dict | None = None,
cookies: dict | None = None,
concurrent_pre_task: Callable[..., Awaitable[None]] | None = None,
pre_task_func: Callable[..., Awaitable[None]] | None = None,
concurrent_pre_task_func: Callable[..., Awaitable[None]] | None = None,
use_tls: bool = False,
**kwargs,
):
@@ -212,7 +213,12 @@ async def execute_monitor_logic(
proxies: Proxies applied to the session.
headers: Headers applied to the session.
cookies: Cookies applied to the base session; ignored for TLS.
concurrent_pre_task: Optional awaitable run once per cycle, gathered
pre_task_func: Optional awaitable run once per cycle, awaited before any
category tasks are dispatched and receiving session and **kwargs.
Use it for setup the category tasks depend on (session headers,
cookies, fetched state); if it raises an expected task error the
cycle is skipped and retried after the usual delay.
concurrent_pre_task_func: Optional awaitable run once per cycle, gathered
alongside the category tasks and receiving session and **kwargs.
Category tasks must not depend on its side effects (session
headers, cookies, fetched state) since no ordering is guaranteed.
@@ -245,9 +251,14 @@ async def execute_monitor_logic(
]
category_keys = list(category_identifiers)
if concurrent_pre_task:
tasks.append(concurrent_pre_task(session=session, **kwargs))
category_keys.append("pre_task")
if pre_task_func:
try:
await pre_task_func(session=session, **kwargs)
except EXPECTED_TASK_ERRORS as error:
LOGGER.warning("Failed to get products", exc_info=error)
except Exception:
LOGGER.exception("Unexpected error")
raise
results = await asyncio.gather(*tasks, return_exceptions=True)
for category_identifier, result in zip(category_keys, results):