Skip to content

Commit

Permalink
Exit early on sigint or cron shutdown #198
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Feb 5, 2025
1 parent 2292fcc commit 91cefe2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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']);

0 comments on commit 91cefe2

Please sign in to comment.