Skip to content

Commit 138fdf0

Browse files
authored
Merge pull request #13401 from nextcloud/improve-lookup-server-behaviour
improve lookup server behaviour
2 parents bbb168a + f6b0a65 commit 138fdf0

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class RetryJob extends Job {
3636
private $jobList;
3737
/** @var string */
3838
private $lookupServer;
39-
/** @var int how much time should be between two tries (10 minutes) */
40-
private $interval = 600;
39+
/** @var int how much time should be between two, will be increased for each retry */
40+
private $interval = 100;
4141

4242
/**
4343
* @param IClientService $clientService
@@ -75,7 +75,7 @@ public function execute($jobList, ILogger $logger = null) {
7575
}
7676

7777
protected function run($argument) {
78-
if ($argument['retryNo'] === 5 || empty($this->lookupServer)) {
78+
if ($this->killBackgroundJob((int)$argument['retryNo'])) {
7979
return;
8080
}
8181

@@ -108,6 +108,27 @@ protected function run($argument) {
108108
* @return bool
109109
*/
110110
protected function shouldRun($argument) {
111-
return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval);
111+
$retryNo = (int)$argument['retryNo'];
112+
$delay = $this->interval * 6 ** $retryNo;
113+
return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay);
114+
}
115+
116+
/**
117+
* check if we should kill the background job
118+
*
119+
* The lookup server should no longer be contacted if:
120+
*
121+
* - max retries are reached (set to 5)
122+
* - lookup server was disabled by the admin
123+
* - no valid lookup server URL given
124+
*
125+
* @param int $retryCount
126+
* @return bool
127+
*/
128+
protected function killBackgroundJob($retryCount) {
129+
$maxTriesReached = $retryCount >= 5;
130+
$lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes';
131+
132+
return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer);
112133
}
113134
}

apps/lookup_server_connector/lib/UpdateLookupServer.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class UpdateLookupServer {
4646
private $jobList;
4747
/** @var string URL point to lookup server */
4848
private $lookupServer;
49+
/** @var bool */
50+
private $lookupServerEnabled;
4951

5052
/**
5153
* @param AccountManager $accountManager
@@ -68,6 +70,8 @@ public function __construct(AccountManager $accountManager,
6870
return;
6971
}
7072

73+
$this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes';
74+
7175
$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
7276
if(!empty($this->lookupServer)) {
7377
$this->lookupServer = rtrim($this->lookupServer, '/');
@@ -79,7 +83,8 @@ public function __construct(AccountManager $accountManager,
7983
* @param IUser $user
8084
*/
8185
public function userUpdated(IUser $user) {
82-
if(empty($this->lookupServer)) {
86+
87+
if (!$this->shouldUpdateLookupServer()) {
8388
return;
8489
}
8590

@@ -150,4 +155,17 @@ protected function sendToLookupServer(IUser $user, array $publicData) {
150155
);
151156
}
152157
}
158+
159+
/**
160+
* check if we should update the lookup server, we only do it if
161+
*
162+
* * we have a valid URL
163+
* * the lookup server update was enabled by the admin
164+
*
165+
* @return bool
166+
*/
167+
private function shouldUpdateLookupServer() {
168+
return $this->lookupServerEnabled || !empty($this->lookupServer);
169+
}
170+
153171
}

0 commit comments

Comments
 (0)