Skip to content
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

Exit early on sigint or cron shutdown #198 #199

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions classes/robot/crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ public function process_queue($verbose = false) {

// While we are not exceeding the maxcron time, and the queue is not empty.
while ($hastime) {

if (\core\local\cli\shutdown::should_gracefully_exit() ||
\core\task\manager::static_caches_cleared_since($cronstart)) {
if ($verbose) {
echo "Shutting down crawler early\n";
}
return true;
}

if (empty($nodes)) {
// Grab a list of items from the front of the queue. We need the first 1000
// in case other workers are already locked and processing items at the front of the queue.
Expand Down
2 changes: 2 additions & 0 deletions cli/crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
die();
}

\core\local\cli\shutdown::script_supports_graceful_exit();

tool_crawler_crawl($options['verbose']);

Loading