Skip to content

Commit a46ca94

Browse files
authored
Merge pull request #12197 from nextcloud/backport/12188/revert-wait-for-cron
[stable14] Revert "Wait for cron to finish before running upgrade command"
2 parents fd39fba + b292f91 commit a46ca94

File tree

5 files changed

+12
-76
lines changed

5 files changed

+12
-76
lines changed

core/Command/Upgrade.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
9999
$this->config,
100100
\OC::$server->getIntegrityCodeChecker(),
101101
$this->logger,
102-
$this->installer,
103-
\OC::$server->getJobList()
102+
$this->installer
104103
);
105104

106105
$dispatcher = \OC::$server->getEventDispatcher();
@@ -192,9 +191,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
192191
$updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) {
193192
$output->writeln('<info>Maintenance mode is kept active</info>');
194193
});
195-
$updater->listen('\OC\Updater', 'waitForCronToFinish', function () use($output) {
196-
$output->writeln('<info>Waiting for cron to finish (checks again in 5 seconds) …</info>');
197-
});
198194
$updater->listen('\OC\Updater', 'updateEnd',
199195
function ($success) use($output, $self) {
200196
if ($success) {

core/ajax/update.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public function handleRepairFeedback($event) {
119119
$config,
120120
\OC::$server->getIntegrityCodeChecker(),
121121
$logger,
122-
\OC::$server->query(\OC\Installer::class),
123-
\OC::$server->getJobList()
122+
\OC::$server->query(\OC\Installer::class)
124123
);
125124
$incompatibleApps = [];
126125

@@ -153,9 +152,6 @@ public function handleRepairFeedback($event) {
153152
$updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
154153
$eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
155154
});
156-
$updater->listen('\OC\Updater', 'waitForCronToFinish', function () use ($eventSource, $l) {
157-
$eventSource->send('success', (string)$l->t('Waiting for cron to finish (checks again in 5 seconds) …'));
158-
});
159155
$updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) {
160156
$eventSource->send('success', (string)$l->t('Updating database schema'));
161157
});

lib/private/BackgroundJob/JobList.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class JobList implements IJobList {
4848
/**@var ITimeFactory */
4949
protected $timeFactory;
5050

51-
/** @var int - 12 hours * 3600 seconds*/
52-
private $jobTimeOut = 43200;
53-
5451
/**
5552
* @param IDBConnection $connection
5653
* @param IConfig $config
@@ -186,7 +183,7 @@ public function getNext() {
186183
$query = $this->connection->getQueryBuilder();
187184
$query->select('*')
188185
->from('jobs')
189-
->where($query->expr()->lte('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
186+
->where($query->expr()->lte('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - 12 * 3600, IQueryBuilder::PARAM_INT)))
190187
->andWhere($query->expr()->lte('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT)))
191188
->orderBy('last_checked', 'ASC')
192189
->setMaxResults(1);
@@ -346,39 +343,4 @@ public function setExecutionTime(IJob $job, $timeTaken) {
346343
->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
347344
$query->execute();
348345
}
349-
350-
/**
351-
* checks if a job is still running (reserved_at time is smaller than 12 hours ago)
352-
*
353-
* Background information:
354-
*
355-
* The 12 hours is the same timeout that is also used to re-schedule an non-terminated
356-
* job (see getNext()). The idea here is to give a job enough time to run very
357-
* long but still be able to recognize that it maybe crashed and re-schedule it
358-
* after the timeout. It's more likely to be crashed at that time than it ran
359-
* that long.
360-
*
361-
* In theory it could lead to an nearly endless loop (as in - at most 12 hours).
362-
* The cron command will not start new jobs when maintenance mode is active and
363-
* this method is only executed in maintenance mode (see where it is called in
364-
* the upgrader class. So this means in the worst case we wait 12 hours when a
365-
* job has crashed. On the other hand: then the instance should be fixed anyways.
366-
*
367-
* @return bool
368-
*/
369-
public function isAnyJobRunning(): bool {
370-
$query = $this->connection->getQueryBuilder();
371-
$query->select('*')
372-
->from('jobs')
373-
->where($query->expr()->gt('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
374-
->setMaxResults(1);
375-
$result = $query->execute();
376-
$row = $result->fetch();
377-
$result->closeCursor();
378-
379-
if ($row) {
380-
return true;
381-
}
382-
return false;
383-
}
384346
}

lib/private/Updater.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use OC\Hooks\BasicEmitter;
3939
use OC\IntegrityCheck\Checker;
4040
use OC_App;
41-
use OCP\BackgroundJob\IJobList;
4241
use OCP\IConfig;
4342
use OCP\ILogger;
4443
use OCP\Util;
@@ -67,9 +66,6 @@ class Updater extends BasicEmitter {
6766
/** @var Installer */
6867
private $installer;
6968

70-
/** @var IJobList */
71-
private $jobList;
72-
7369
private $logLevelNames = [
7470
0 => 'Debug',
7571
1 => 'Info',
@@ -78,16 +74,20 @@ class Updater extends BasicEmitter {
7874
4 => 'Fatal',
7975
];
8076

77+
/**
78+
* @param IConfig $config
79+
* @param Checker $checker
80+
* @param ILogger $log
81+
* @param Installer $installer
82+
*/
8183
public function __construct(IConfig $config,
8284
Checker $checker,
83-
ILogger $log,
84-
Installer $installer,
85-
IJobList $jobList) {
85+
ILogger $log = null,
86+
Installer $installer) {
8687
$this->log = $log;
8788
$this->config = $config;
8889
$this->checker = $checker;
8990
$this->installer = $installer;
90-
$this->jobList = $jobList;
9191
}
9292

9393
/**
@@ -114,11 +114,6 @@ public function upgrade() {
114114
$installedVersion = $this->config->getSystemValue('version', '0.0.0');
115115
$currentVersion = implode('.', \OCP\Util::getVersion());
116116

117-
// see https://github.com/nextcloud/server/issues/9992 for potential problem
118-
if (version_compare($installedVersion, '14.0.0.9', '>=')) {
119-
$this->waitForCronToFinish();
120-
}
121-
122117
$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
123118

124119
$success = true;
@@ -617,12 +612,6 @@ private function logAllEvents() {
617612
});
618613

619614
}
620-
private function waitForCronToFinish() {
621-
while ($this->jobList->isAnyJobRunning()) {
622-
$this->emit('\OC\Updater', 'waitForCronToFinish');
623-
sleep(5);
624-
}
625-
}
626615

627616
}
628617

tests/lib/UpdaterTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
use OC\Installer;
2626
use OC\Updater;
27-
use OCP\BackgroundJob\IJobList;
2827
use OCP\IConfig;
2928
use OCP\ILogger;
3029
use OC\IntegrityCheck\Checker;
@@ -40,8 +39,6 @@ class UpdaterTest extends TestCase {
4039
private $checker;
4140
/** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
4241
private $installer;
43-
/** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
44-
private $jobList;
4542

4643
public function setUp() {
4744
parent::setUp();
@@ -57,16 +54,12 @@ public function setUp() {
5754
$this->installer = $this->getMockBuilder(Installer::class)
5855
->disableOriginalConstructor()
5956
->getMock();
60-
$this->jobList = $this->getMockBuilder(IJobList::class)
61-
->disableOriginalConstructor()
62-
->getMock();
6357

6458
$this->updater = new Updater(
6559
$this->config,
6660
$this->checker,
6761
$this->logger,
68-
$this->installer,
69-
$this->jobList
62+
$this->installer
7063
);
7164
}
7265

0 commit comments

Comments
 (0)