diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-04-23 05:01:00 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2018-04-23 05:01:00 +0300 |
commit | 9bed2959276b4b2cb9959ba0a5aab23a1297f488 (patch) | |
tree | c04f34f01ceab620275dfb82f514ecf73924276a /core/CronArchive | |
parent | f56a26f27b0545be8b02e83f7f4a105d02496e45 (diff) |
Make sure core:archive terminates when all initial websites have been processed (#12716)
* Make sure core:archive terminates when all initial websites have been processed
* Update CronArchive.php
* better detection of when the initial queue has been processed
Diffstat (limited to 'core/CronArchive')
-rw-r--r-- | core/CronArchive/SharedSiteIds.php | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/CronArchive/SharedSiteIds.php b/core/CronArchive/SharedSiteIds.php index f77f3d3fdc..95779631d1 100644 --- a/core/CronArchive/SharedSiteIds.php +++ b/core/CronArchive/SharedSiteIds.php @@ -29,6 +29,7 @@ class SharedSiteIds private $siteIds = array(); private $currentSiteId; private $done = false; + private $numWebsitesLeftToProcess; public function __construct($websiteIds, $optionName = self::OPTION_DEFAULT) { @@ -52,6 +53,7 @@ class SharedSiteIds return $websiteIds; }); + $this->numWebsitesLeftToProcess = $this->getNumSites(); } public function getInitialSiteIds() @@ -154,6 +156,12 @@ class SharedSiteIds */ public function getNextSiteId() { + if ($this->done) { + // we make sure we don't check again whether there are more sites to be archived as the list of + // sharedSiteIds may have been reset by now. + return null; + } + $self = $this; $this->currentSiteId = $this->runExclusive(function () use ($self) { @@ -161,9 +169,18 @@ class SharedSiteIds $siteIds = $self->getAllSiteIdsToArchive(); if (empty($siteIds)) { + // done... no sites left to be archived return null; } + if (count($siteIds) > $self->numWebsitesLeftToProcess) { + // done... the number of siteIds in SharedSiteIds is larger than it was initially... therefore it must have + // been reset at some point. + return null; + } + + $self->numWebsitesLeftToProcess = count($siteIds); + $nextSiteId = array_shift($siteIds); $self->setSiteIdsToArchive($siteIds); @@ -172,6 +189,7 @@ class SharedSiteIds if (is_null($this->currentSiteId)) { $this->done = true; + $this->numWebsitesLeftToProcess = 0; } return $this->currentSiteId; |