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

Cache crawler - run within a certain range of time only #621

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
Changes to default value + instance usage
Tymotey committed Mar 4, 2024
commit 06e501fd58d0df993b9531381e6a556f48795cf2
2 changes: 1 addition & 1 deletion src/base.cls.php
Original file line number Diff line number Diff line change
@@ -515,7 +515,7 @@ class Base extends Root

// Crawler
self::O_CRAWLER => false,
self::O_CRAWLER_SCHEDULE_TIME => '00:00-23:59',
self::O_CRAWLER_SCHEDULE_TIME => '',
self::O_CRAWLER_USLEEP => 0,
self::O_CRAWLER_RUN_DURATION => 0,
self::O_CRAWLER_RUN_INTERVAL => 0,
30 changes: 17 additions & 13 deletions src/crawler.cls.php
Original file line number Diff line number Diff line change
@@ -257,20 +257,25 @@ public static function _crawler_in_schedule_time()
$now = new DateTime();
$class_settings = self::cls();
$schedule_times = $class_settings->conf(Base::O_CRAWLER_SCHEDULE_TIME, '');
$schedule_times = explode(',', $schedule_times);

foreach ($schedule_times as $time) {
if ($time !== '') {
$hours = explode('-', $time);
$start = new DateTime($hours[0] . ":00");
$end = new DateTime($hours[1] . ":00");
if ($now < $end && $now > $start) {
return true;
if($schedule_times!== ''){
$schedule_times = explode(',', $schedule_times);

foreach ($schedule_times as $time) {
if ($time !== '') {
$hours = explode('-', $time);
$start = new DateTime($hours[0] . ":00");
$end = new DateTime($hours[1] . ":00");
if ($now < $end && $now > $start) {
return true;
}
}
}

return false;
}
else{
return true;
}

return false;
}

/**
@@ -281,13 +286,12 @@ public static function _crawler_in_schedule_time()
*/
public static function start($manually_run = false)
{
$crawler_is_in_time = self::_crawler_in_schedule_time();

if (!Router::can_crawl()) {
self::debug('......crawler is NOT allowed by the server admin......');
return false;
}

$crawler_is_in_time = self::cls()->_crawler_in_schedule_time();
if (!$manually_run && !$crawler_is_in_time) {
self::debug('......crawler is NOT allowed in this time slot......');
return false;