diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-04-23 05:01:28 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2018-04-23 05:01:28 +0300 |
commit | f0ced619613b32d29d6534388ad6a9a0240f4cc9 (patch) | |
tree | ab427d28b70f5bf3ce7ad4d6ec20c909f1f4be6f /core/CliMulti.php | |
parent | 9bed2959276b4b2cb9959ba0a5aab23a1297f488 (diff) |
Do not run the same archive command twice (#12702)
* Do not run the same archive command twice
* simplify
* During core:archive when a day or period archiving fails for a website, abort the website archiving (#12708)
* If one of the period archiving fails, we now cancel the remaining archiving processes
* Increment the skipped counter
* also exit when a day period is already active
* undo last commit
* if day archive fails, then do not proceed archiving periods
* Minor changes
* Archive: mark the daily archive as successful, only after it was really successful (#12720)
+ Simplify & fix some logic
* do not archive a period when a sub period is processing (#12719)
Diffstat (limited to 'core/CliMulti.php')
-rw-r--r-- | core/CliMulti.php | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/core/CliMulti.php b/core/CliMulti.php index ef360f0214..3e092d84b4 100644 --- a/core/CliMulti.php +++ b/core/CliMulti.php @@ -148,13 +148,18 @@ class CliMulti $this->outputs[] = $output; } - private function buildCommand($hostname, $query, $outputFile) + private function buildCommand($hostname, $query, $outputFile, $doEsacpeArg = true) { $bin = $this->findPhpBinary(); $superuserCommand = $this->runAsSuperUser ? "--superuser" : ""; + if ($doEsacpeArg) { + $hostname = escapeshellarg($hostname); + $query = escapeshellarg($query); + } + return sprintf('%s %s %s/console climulti:request -q --piwik-domain=%s %s %s > %s 2>&1 &', - $bin, $this->phpCliOptions, PIWIK_INCLUDE_PATH, escapeshellarg($hostname), $superuserCommand, escapeshellarg($query), $outputFile); + $bin, $this->phpCliOptions, PIWIK_INCLUDE_PATH, $hostname, $superuserCommand, $query, $outputFile); } private function getResponse() @@ -266,6 +271,34 @@ class CliMulti return StaticContainer::get('path.tmp') . '/climulti'; } + public function isCommandAlreadyRunning($url) + { + if (!$this->supportsAsync) { + // we cannot detect if web archive is still running + return false; + } + + $query = UrlHelper::getQueryFromUrl($url, array('pid' => 'removeme')); + $hostname = Url::getHost($checkIfTrusted = false); + $commandToCheck = $this->buildCommand($hostname, $query, $output = '', $escape = false); + + $currentlyRunningJobs = `ps aux`; + + $posStart = strpos($commandToCheck, 'console climulti'); + $posPid = strpos($commandToCheck, '&pid='); // the pid is random each time so we need to ignore it. + $shortendCommand = substr($commandToCheck, $posStart, $posPid - $posStart); + // equals eg console climulti:request -q --piwik-domain= --superuser module=API&method=API.get&idSite=1&period=month&date=2018-04-08,2018-04-30&format=php&trigger=archivephp + $shortendCommand = preg_replace("/([&])date=.*?(&|$)/", "", $shortendCommand); + $currentlyRunningJobs = preg_replace("/([&])date=.*?(&|$)/", "", $currentlyRunningJobs); + + if (strpos($currentlyRunningJobs, $shortendCommand) !== false) { + Log::debug($shortendCommand . ' is already running'); + return true; + } + + return false; + } + private function executeAsyncCli($url, Output $output, $cmdId) { $this->processes[] = new Process($cmdId); |