Merge pull request #28013 from nextcloud/jitter-appstore-and-updater-server-pinging

pull/28360/head
John Molakvoæ 2021-08-09 19:30:12 +07:00 committed by GitHub
commit 5bd91eac31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

@ -60,17 +60,12 @@ class BackgroundJob extends TimedJob {
/** @var string[] */ /** @var string[] */
protected $users; protected $users;
/** public function __construct(IConfig $config,
* NotificationBackgroundJob constructor. IManager $notificationManager,
* IGroupManager $groupManager,
* @param IConfig $config IAppManager $appManager,
* @param IManager $notificationManager IClientService $client,
* @param IGroupManager $groupManager Installer $installer) {
* @param IAppManager $appManager
* @param IClientService $client
* @param Installer $installer
*/
public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) {
// Run once a day // Run once a day
$this->setInterval(60 * 60 * 24); $this->setInterval(60 * 60 * 24);
@ -83,6 +78,16 @@ class BackgroundJob extends TimedJob {
} }
protected function run($argument) { protected function run($argument) {
if (\OC::$CLI && !$this->config->getSystemValueBool('debug', false)) {
try {
// Jitter the pinging of the updater server and the appstore a bit.
// Otherwise all Nextcloud installations are pinging the servers
// in one of 288
sleep(random_int(1, 180));
} catch (\Exception $e) {
}
}
$this->checkCoreUpdate(); $this->checkCoreUpdate();
$this->checkAppUpdates(); $this->checkAppUpdates();
} }

@ -107,6 +107,10 @@ class BackgroundJobTest extends TestCase {
$job->expects($this->once()) $job->expects($this->once())
->method('checkAppUpdates'); ->method('checkAppUpdates');
$this->config->method('getSystemValueBool')
->with('debug', false)
->willReturn(true);
self::invokePrivate($job, 'run', [null]); self::invokePrivate($job, 'run', [null]);
} }