Skip to content

Add a shouldStopCallback hook for graceful external stops#504

Merged
freekmurze merged 2 commits intospatie:mainfrom
kissifrot:feature/should-stop-callback
Apr 15, 2026
Merged

Add a shouldStopCallback hook for graceful external stops#504
freekmurze merged 2 commits intospatie:mainfrom
kissifrot:feature/should-stop-callback

Conversation

@kissifrot
Copy link
Copy Markdown
Contributor

Add a shouldStopCallback hook for graceful external stops

  • Some applications need to stop an active crawl based on external state, such as a database flag, an admin action, or a feature toggle.
  • Today, the only graceful stop mechanism is the internal shouldStop flag, which makes these integrations awkward and pushes tests toward mutating internal state.
  • This adds a fluent shouldStopCallback() hook that is evaluated before scheduling each next request. When it returns true, the crawl stops gracefully and start() returns FinishReason::Interrupted.

@kissifrot
Copy link
Copy Markdown
Contributor Author

Little ping @freekmurze 🙏

Copy link
Copy Markdown
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation that follows the existing fluent API patterns. Good phpdoc, the callback is only invoked when set (no perf impact for existing users), and test coverage covers both immediate and mid-crawl stops. CI is green across all matrix jobs.

@freekmurze freekmurze merged commit 1b9ce60 into spatie:main Apr 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants