diff --git a/classes/robot/crawler.php b/classes/robot/crawler.php index b1164651..c8846d78 100644 --- a/classes/robot/crawler.php +++ b/classes/robot/crawler.php @@ -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. diff --git a/cli/crawler.php b/cli/crawler.php index 2f64929a..f83d9e2c 100644 --- a/cli/crawler.php +++ b/cli/crawler.php @@ -52,5 +52,7 @@ die(); } +\core\local\cli\shutdown::script_supports_graceful_exit(); + tool_crawler_crawl($options['verbose']);