Skip to content

Commit c37fe02

Browse files
committedFeb 5, 2025
Exit early on sigint or cron shutdown #198
1 parent 2292fcc commit c37fe02

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎classes/robot/crawler.php

+9
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ public function process_queue($verbose = false) {
534534

535535
// While we are not exceeding the maxcron time, and the queue is not empty.
536536
while ($hastime) {
537+
538+
if (\core\local\cli\shutdown::should_gracefully_exit() ||
539+
\core\task\manager::static_caches_cleared_since($cronstart)) {
540+
if ($verbose) {
541+
echo "Shutting down crawler early\n";
542+
}
543+
return true;
544+
}
545+
537546
if (empty($nodes)) {
538547
// Grab a list of items from the front of the queue. We need the first 1000
539548
// in case other workers are already locked and processing items at the front of the queue.

‎cli/crawler.php

+2
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@
5252
die();
5353
}
5454

55+
\core\local\cli\shutdown::script_supports_graceful_exit();
56+
5557
tool_crawler_crawl($options['verbose']);
5658

0 commit comments

Comments
 (0)