diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2020-09-13 23:56:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-13 23:56:30 +0300 |
commit | ef5b1ece3fcb9331eefdef26056664ff48bef95d (patch) | |
tree | e4237a681ed48915388e903f00fa64ad8891a8da /core | |
parent | b211b49bf0655397e7bd6f4a356b68bb2e6ad79f (diff) |
Add back db reconnect code to core:archive. (#16432)
* Add back db reconnect code to core:archive. Was probably removed because methods it was used in were removed when refactoring.
* Add the DB disconnect right after executing an archive request so it can't time out before starting a new archive
Co-authored-by: Thomas Steur <tsteur@users.noreply.github.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/CronArchive.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/CronArchive.php b/core/CronArchive.php index dd4e39c29e..6533e6d6ce 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -170,6 +170,8 @@ class CronArchive private $formatter; + private $lastDbReset = false; + /** * @var SegmentArchiving */ @@ -369,6 +371,8 @@ class CronArchive $numArchivesFinished += $successCount; } + $this->disconnectDb(); + $this->logger->info("Done archiving!"); $this->logSection("SUMMARY"); @@ -436,6 +440,9 @@ class CronArchive $cliMulti->timeRequests(); $responses = $cliMulti->request($urls); + + $this->disconnectDb(); + $timers = $cliMulti->getTimers(); $successCount = 0; @@ -575,6 +582,8 @@ class CronArchive return; } + $this->disconnectDb(); + // TODO: this is a HACK to get the purgeOutdatedArchives task to work when run below. without // it, the task will not run because we no longer run the tasks through CliMulti. // harder to implement alternatives include: @@ -588,6 +597,18 @@ class CronArchive $this->logSection(""); } + private function disconnectDb() + { + $twoHoursInSeconds = 60 * 60 * 2; + + if (time() > ($this->lastDbReset + $twoHoursInSeconds)) { + // we aim to through DB connections away only after 2 hours + $this->lastDbReset = time(); + Db::destroyDatabaseObject(); + Tracker::disconnectCachedDbConnection(); + } + } + /** * Returns base URL to process reports for the $idSite on a given $period * |