diff options
author | Peter Zhang <peter@innocraft.com> | 2022-01-21 17:45:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 17:45:12 +0300 |
commit | b277655b9163ca0181a67087be6c0dcaea63dc20 (patch) | |
tree | e48b36a2a76163ba7197440dae457cce6f2a1bc1 /core | |
parent | 1e26baf4dc0eec3eba84d1f0422a95f5835252e9 (diff) |
disable cron task when segment is deleted (#18383)
* Update Segment.php
add function
* update segment on cron when is deleted
update segment on cron when is deleted
* Update QueueConsumer.php
change to check segement
* Update QueueConsumer.php
remove used function
* Update QueueConsumer.php
update Segment availbel
* Update QueueConsumer.php
update queue
* Update QueueConsumer.php
trigger update
* update
update
* Update QueueConsumer.php
remove plugin check
* Revert "Update QueueConsumer.php"
This reverts commit e059f4b7f3eef4e0807987e3f0bb09fc12cd0bf8.
* Update QueueConsumer.php
remove the right part
* Update core/CronArchive/QueueConsumer.php
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* try simple solution
try simple solution
* Adds invalid segment test case
* fix segment errors
fix segment errors
* Update CronArchiveInvalidSegmentTest.php
update tests
* Update CronArchiveInvalidSegmentTest.php
update tests
* update tests
update tests
* update tests and words
update tests and words
* update log info and tests
update log info and tests
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/CronArchive.php | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/core/CronArchive.php b/core/CronArchive.php index 4a8204ef02..dcde1460fc 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -497,7 +497,7 @@ class CronArchive foreach ($urls as $index => $url) { $content = array_key_exists($index, $responses) ? $responses[$index] : null; - $this->checkResponse($content, $url); + $checkInvalid = $this->checkResponse($content, $url); $stats = json_decode($content, $assoc = true); if (!is_array($stats)) { @@ -514,7 +514,10 @@ class CronArchive $visitsForPeriod = $this->getVisitsFromApiResponse($stats); - $this->logArchiveJobFinished($url, $timers[$index], $visitsForPeriod, $archivesBeingQueried[$index]['plugin'], $archivesBeingQueried[$index]['report']); + + $this->logArchiveJobFinished($url, $timers[$index], $visitsForPeriod, + $archivesBeingQueried[$index]['plugin'], $archivesBeingQueried[$index]['report'], !$checkInvalid); + $this->deleteInvalidatedArchives($archivesBeingQueried[$index]); @@ -572,12 +575,14 @@ class CronArchive return [$url, $segment, $plugin]; } - private function logArchiveJobFinished($url, $timer, $visits, $plugin = null, $report = null) + private function logArchiveJobFinished($url, $timer, $visits, $plugin = null, $report = null, $wasSkipped = null) { $params = UrlHelper::getArrayFromQueryString($url); $visits = (int) $visits; - $this->logger->info("Archived website id {$params['idSite']}, period = {$params['period']}, date = " + $message = $wasSkipped ? "Skipped Archiving website" : "Archived website"; + + $this->logger->info($message." id {$params['idSite']}, period = {$params['period']}, date = " . "{$params['date']}, segment = '" . (isset($params['segment']) ? urldecode(urldecode($params['segment'])) : '') . "', " . ($plugin ? "plugin = $plugin, " : "") . ($report ? "report = $report, " : "") . "$visits visits found. $timer"); } @@ -715,6 +720,12 @@ class CronArchive private function logNetworkError($url, $response) { + + if (preg_match("/Segment (.*?) is not a supported segment/i", $response, $match)) { + $this->logger->info($match[0]); + return false; + } + $message = "Got invalid response from API request: $url. "; if (empty($response)) { $message .= "The response was empty. This usually means a server error. A solution to this error is generally to increase the value of 'memory_limit' in your php.ini file. "; @@ -919,6 +930,11 @@ class CronArchive } foreach ($this->segmentArchiving->getAllSegmentsToArchive($idSite) as $segmentDefinition) { + + // check if the segment is available + if (!$this->isSegmentAvailable($segmentDefinition, [$idSite])) { + continue; + } $params = new Parameters(new Site($idSite), $periodObj, new Segment($segmentDefinition, [$idSite], $periodObj->getDateStart(), $periodObj->getDateEnd())); if ($this->canWeSkipInvalidatingBecauseThereIsAUsablePeriod($params, $doNotIncludeTtlInExistingArchiveCheck)) { $this->logger->debug(' Found usable archive for {archive}, skipping invalidation.', ['archive' => $params]); @@ -947,6 +963,24 @@ class CronArchive } } + + /** + * check if segments that contain dimensions that don't exist anymore + * @param $segmentDefinition + * @param $idSites + * @return bool + */ + protected function isSegmentAvailable($segmentDefinition, $idSites) + { + try { + new Segment($segmentDefinition, $idSites); + } catch (\Exception $e) { + $this->logger->info("Segment '".$segmentDefinition."' is not a supported segment"); + return false; + } + return true; + } + /** * Returns true if there is an existing valid period we can use, or false if there isn't and the invalidation should go through. * |