feat: add experimental monitor mode to BasicCrawler#3553
Open
hiepau1231 wants to merge 9 commits intoapify:masterfrom
Open
feat: add experimental monitor mode to BasicCrawler#3553hiepau1231 wants to merge 9 commits intoapify:masterfrom
hiepau1231 wants to merge 9 commits intoapify:masterfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…olved) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a new Monitor class that renders a compact real-time status block to process.stderr during a crawl. In TTY mode the block overwrites itself in-place; in non-TTY mode (CI, pipes) it prints plain lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12 tests covering: construction, start/stop lifecycle, buildLines() output content, TTY vs non-TTY rendering, and stderr write behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a `monitor` boolean option to BasicCrawlerOptions. When true, a Monitor instance is created at the start of `run()` and stopped in the `finally` block, ensuring it always cleans up even if the crawl throws. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 integration tests verifying that: - crawl completes normally with monitor: true - crawl completes normally with monitor: false (default) - errors still propagate to failedRequestHandler when monitor is active Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… CPU, unref timer, 4 new tests - Add `monitorOptions?: MonitorOptions` to `BasicCrawlerOptions` and pass it through to the `Monitor` constructor so callers can configure `intervalSecs` without monkey-patching. - Skip the periodic status-message logger when `monitor: true` is set to prevent ANSI cursor-control sequences from being interleaved with plain log lines. - Guard ETA against negative values when `finished > total` (approximate counts from `RequestManagerTandem`): clamp remaining to ≥ 0. - Show `CPU: N/A` on Windows where `os.loadavg()` always returns zeros. - Call `.unref()` on the interval so the monitor cannot prevent process exit. - Remove internal planning docs (spec/plan) from the repository. - Add 4 tests: negative-ETA guard, Windows CPU label, intervalSecs config, and improve cursor-overwrite assertion. Closes apify#2680 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2680
Continues the work from #2692, addressing all reviewer feedback and adding missing tests.
What changed
packages/core/src/crawlers/monitor.tsfinished > total(approximate counts fromRequestManagerTandem) —Math.max(0, remaining)CPU: N/Aon Windows whereos.loadavg()always returns[0,0,0].unref()on the interval so the monitor cannot prevent process exitpackages/basic-crawler/src/internals/basic-crawler.tsmonitorOptions?: MonitorOptionstoBasicCrawlerOptionsso callers can configureintervalSecsand other options without monkey-patchingthis.monitorOptionsthrough to theMonitorconstructorstatusMessageLoggingIntervalperiodic logger whenmonitor: trueis active to avoid plain log lines being interleaved with ANSI cursor-control sequencestest/core/crawlers/monitor.test.tsN/Alabel,intervalSecsconfig, improved cursor-overwrite assertion (15 total, all passing)All 65 existing
basic_crawler.test.tstests continue to pass.Usage