-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add StatusMessageRedirector
#407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Update test to be able to use caplog
Refactor tests and code to reuse code.
Update default logger to not duplicate handlers if already exists
Have explicit start and stop instead of __call__
Update test data to properly match the reality with line endings
Naming.
Add final timeout.
Example log of recursive Actor run with highlighted redirected status messages Example Actor: |
e903a68
to
18f4f51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds the new StatusMessageRedirector
utility to stream status and status messages from a target Actor run (both shallow and deep redirection), integrates it into the client APIs, and updates tests to cover the new behavior.
- Introduce
StatusMessageRedirector
(sync & async) inlog.py
- Add
get_status_message_redirector
toRunClient
(sync & async) inrun.py
- Hook status redirection into
ActorClient.call
(sync & async) inactor.py
- Update and extend
test_logging.py
to exercise status message streaming
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/unit/test_logging.py | Add fixtures and new tests for StatusMessageRedirector |
src/apify_client/clients/resource_clients/run.py | New get_status_message_redirector methods for sync and async runs |
src/apify_client/clients/resource_clients/log.py | Core StatusMessageRedirector , StatusMessageRedirectorSync/Async |
src/apify_client/clients/resource_clients/actor.py | Wire up status redirector into ActorClient.call sync & async variants |
Comments suppressed due to low confidence (5)
tests/unit/test_logging.py:386
- [nitpick] We should also add a test for the manual
start()
/stop()
usage ofStatusMessageRedirector
(outside of a context manager) to ensure that flow is covered.
@respx.mock
src/apify_client/clients/resource_clients/run.py:349
create_redirect_logger
is used here but not imported; addfrom apify_client._logging import create_redirect_logger
at the top.
to_logger = create_redirect_logger(f'apify.{name}')
src/apify_client/clients/resource_clients/log.py:455
asyncio.create_task
is called butasyncio
is not imported; addimport asyncio
.
self._logging_task = asyncio.create_task(self._log_changed_status_message())
tests/unit/test_logging.py:168
- This fixture mutates a class‐level variable without resetting it, which can leak state across tests; consider using
yield
and restoring the original value after the test.
StatusMessageRedirector._force_propagate = True
src/apify_client/clients/resource_clients/run.py:337
- Docstring says it returns
StatusMessageRedirector
, but in sync/async methods it actually returnsStatusMessageRedirectorSync
/StatusMessageRedirectorAsync
; clarify the concrete return type.
Returns:
`StatusMessageRedirector` instance for redirected logs.
Description
Add the option to log status and status messages of another Actor run. If such Actor run is also redirecting logs from another Actor run, then those logs can propagate all the way to the top through the
StreamedLog
- deep redirection. If the Actor run from which we are redirecting status messages is not redirecting logs from its children, then the log and status redirection remains shallow - only from that Actor run.Example usage:
Through
ActorClient(Async).call
By default it is turned on, so just calling actor like this already redirects the logs to pre-configured logger:
To turn off, pass
logger=None
Or pass custom logger, if desired:
Through
RunClient(Async).get_status_message_redirector
With context:
Manually:
Issues