Repository navigation
feat: Add since to streamed logs and reopen closed streams
#1253
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
Open
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9a702a2
feat: redirect run logs from a given time and resume after the platfo…
claude 80e1492
refactor: drop stacklevel handling from the `from_start` deprecation …
claude bdfe0e8
feat: expose `StreamedLog.last_redirected_at` and resume reopened str…
claude ef37604
test: e2e test of resuming log redirection after the redirecting Acto…
claude acb39aa
test: remove the one-off reboot e2e test of log redirection
claude 79aaea6
test: e2e test of log redirection from a run that stays silent for si…
claude d49cecf
test: run the silent-run log redirection e2e test in a redirecting Actor
claude 5040025
test: give both Actor runs of the silent-run e2e test enough time
claude 95e0fe7
test: remove the one-off silent-run e2e test of log redirection
claude 7cbea01
refactor: reopen a closed log stream after a fixed pause instead of a…
claude 86429bf
refactor: stop log redirection once the run has finished, without a c…
claude 3133679
Format
Pijukatel c632146
refactor: reopen a log stream only when it broke off
claude 3d4b57f
fix: do not reopen a log stream when processing its data fails
claude 8a0aedb
refactor: reopen a log stream only after a transient transport error
claude f0517a9
fix: keep lines sharing the last timestamp on reopen, and stop reopen…
claude 2729297
docs: drop the v4 upgrading guide until v4 is planned
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from apify_client import ApifyClientAsync | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
| RECORD_KEY = 'LOG_REDIRECTED_UNTIL' | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| apify_client = ApifyClientAsync(TOKEN) | ||
| run_client = apify_client.run('MY-RUN-ID') | ||
| store_client = apify_client.key_value_store('MY-STORE-ID') | ||
|
|
||
| # After a reboot, continue after the last line redirected before it. | ||
| record = await store_client.get_record(RECORD_KEY) | ||
| since = None | ||
| if record: | ||
| since = datetime.fromisoformat(record['value']) + timedelta(milliseconds=1) | ||
|
|
||
| streamed_log = await run_client.get_streamed_log(since=since) | ||
| async with streamed_log: | ||
| await run_client.wait_for_finish() | ||
|
|
||
| # Before a reboot, save how far the redirection got. Here it is saved once the | ||
| # run finishes; save it on your own reboot or migration signal instead. | ||
| if streamed_log.last_redirected_at: | ||
| redirected_until = streamed_log.last_redirected_at.isoformat() | ||
| await store_client.set_record(RECORD_KEY, redirected_until) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from apify_client import ApifyClient | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
| RECORD_KEY = 'LOG_REDIRECTED_UNTIL' | ||
|
|
||
|
|
||
| def main() -> None: | ||
| apify_client = ApifyClient(TOKEN) | ||
| run_client = apify_client.run('MY-RUN-ID') | ||
| store_client = apify_client.key_value_store('MY-STORE-ID') | ||
|
|
||
| # After a reboot, continue after the last line redirected before it. | ||
| record = store_client.get_record(RECORD_KEY) | ||
| since = None | ||
| if record: | ||
| since = datetime.fromisoformat(record['value']) + timedelta(milliseconds=1) | ||
|
|
||
| streamed_log = run_client.get_streamed_log(since=since) | ||
| with streamed_log: | ||
| run_client.wait_for_finish() | ||
|
|
||
| # Before a reboot, save how far the redirection got. Here it is saved once the | ||
| # run finishes; save it on your own reboot or migration signal instead. | ||
| if streamed_log.last_redirected_at: | ||
| redirected_until = streamed_log.last_redirected_at.isoformat() | ||
| store_client.set_record(RECORD_KEY, redirected_until) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.