readded pre_task_func for functions that must promise order
This commit is contained in:
1 parent
83b15231ee
commit
1e0663d972
1 file changed
+11
-5
@@ -193,7 +193,8 @@ async def execute_monitor_logic(
|
|||||||
proxies: AioProxies,
|
proxies: AioProxies,
|
||||||
headers: dict | None = None,
|
headers: dict | None = None,
|
||||||
cookies: 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,
|
use_tls: bool = False,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
@@ -212,7 +213,7 @@ async def execute_monitor_logic(
|
|||||||
proxies: Proxies applied to the session.
|
proxies: Proxies applied to the session.
|
||||||
headers: Headers applied to the session.
|
headers: Headers applied to the session.
|
||||||
cookies: Cookies applied to the base session; ignored for TLS.
|
cookies: Cookies applied to the base session; ignored for TLS.
|
||||||
concurrent_pre_task: Optional awaitable run once per cycle, gathered
|
concurrent_pre_task_func: Optional awaitable run once per cycle, gathered
|
||||||
alongside the category tasks and receiving session and **kwargs.
|
alongside the category tasks and receiving session and **kwargs.
|
||||||
Category tasks must not depend on its side effects (session
|
Category tasks must not depend on its side effects (session
|
||||||
headers, cookies, fetched state) since no ordering is guaranteed.
|
headers, cookies, fetched state) since no ordering is guaranteed.
|
||||||
@@ -245,9 +246,14 @@ async def execute_monitor_logic(
|
|||||||
]
|
]
|
||||||
category_keys = list(category_identifiers)
|
category_keys = list(category_identifiers)
|
||||||
|
|
||||||
if concurrent_pre_task:
|
if pre_task_func:
|
||||||
tasks.append(concurrent_pre_task(session=session, **kwargs))
|
try:
|
||||||
category_keys.append("pre_task")
|
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)
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||||
for category_identifier, result in zip(category_keys, results):
|
for category_identifier, result in zip(category_keys, results):
|
||||||
|
|||||||
Reference in new issue
Block a user