-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Add redirected actor logs #403
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
Changes from 12 commits
a71ae41
69ff84c
862cacc
753427a
cc0d944
cbcabd3
81577e8
b9bc44d
9720327
85ead2f
4ad39fa
74595f9
cba571f
02a1eb2
2674cf2
2a6f2ec
1263450
b1338f1
669a749
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any | ||
from typing import TYPE_CHECKING, Any, Literal | ||
|
||
from apify_shared.utils import ( | ||
filter_out_none_values_recursively, | ||
|
@@ -27,6 +27,7 @@ | |
|
||
if TYPE_CHECKING: | ||
from decimal import Decimal | ||
from logging import Logger | ||
|
||
from apify_shared.consts import ActorJobStatus, MetaOrigin | ||
|
||
|
@@ -289,6 +290,7 @@ def call( | |
timeout_secs: int | None = None, | ||
webhooks: list[dict] | None = None, | ||
wait_secs: int | None = None, | ||
logger: Logger | None | Literal['default'] = 'default', | ||
) -> dict | None: | ||
"""Start the Actor and wait for it to finish before returning the Run object. | ||
|
||
|
@@ -313,6 +315,9 @@ def call( | |
a webhook set up for the Actor, you do not have to add it again here. | ||
wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided, | ||
waits indefinitely. | ||
logger: Logger used to redirect logs from the Actor run. By default, it is set to "default" which means that | ||
the default logger will be created and used. Setting `None` will disable any log propagation. Passing | ||
custom logger will redirect logs to the provided logger. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Um, and what does that actually mean for the caller? Let's try and come up with a better description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to rephrase it like this:
|
||
|
||
Returns: | ||
The run object. | ||
|
@@ -327,8 +332,19 @@ def call( | |
timeout_secs=timeout_secs, | ||
webhooks=webhooks, | ||
) | ||
if not logger: | ||
return self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
|
||
return self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
run_client = self.root_client.run(run_id=started_run['id']) | ||
if logger == 'default': | ||
actor_data = self.get() | ||
actor_name = actor_data.get('name', '') if actor_data else '' | ||
log_context = run_client.get_streamed_log(actor_name=actor_name) | ||
else: | ||
log_context = run_client.get_streamed_log(to_logger=logger) | ||
|
||
with log_context: | ||
return self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
|
||
def build( | ||
self, | ||
|
@@ -681,6 +697,7 @@ async def call( | |
timeout_secs: int | None = None, | ||
webhooks: list[dict] | None = None, | ||
wait_secs: int | None = None, | ||
logger: Logger | None | Literal['default'] = 'default', | ||
) -> dict | None: | ||
"""Start the Actor and wait for it to finish before returning the Run object. | ||
|
||
|
@@ -705,6 +722,9 @@ async def call( | |
a webhook set up for the Actor, you do not have to add it again here. | ||
wait_secs: The maximum number of seconds the server waits for the run to finish. If not provided, | ||
waits indefinitely. | ||
logger: Logger used to redirect logs from the Actor run. By default, it is set to "default" which means that | ||
the default logger will be created and used. Setting `None` will disable any log propagation. Passing | ||
custom logger will redirect logs to the provided logger. | ||
|
||
Returns: | ||
The run object. | ||
|
@@ -720,7 +740,19 @@ async def call( | |
webhooks=webhooks, | ||
) | ||
|
||
return await self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
if not logger: | ||
return await self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
|
||
run_client = self.root_client.run(run_id=started_run['id']) | ||
if logger == 'default': | ||
actor_data = await self.get() | ||
actor_name = actor_data.get('name', '') if actor_data else '' | ||
log_context = await run_client.get_streamed_log(actor_name=actor_name) | ||
else: | ||
log_context = await run_client.get_streamed_log(to_logger=logger) | ||
|
||
async with log_context: | ||
return await self.root_client.run(started_run['id']).wait_for_finish(wait_secs=wait_secs) | ||
|
||
async def build( | ||
self, | ||
|
Uh oh!
There was an error while loading. Please reload this page.