Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class RetryJob extends Job {
private $jobList;
/** @var string */
private $lookupServer;
/** @var int how much time should be between two tries (10 minutes) */
private $interval = 600;
/** @var int how much time should be between two, will be increased for each retry */
private $interval = 100;

/**
* @param IClientService $clientService
Expand Down Expand Up @@ -75,7 +75,7 @@ public function execute($jobList, ILogger $logger = null) {
}

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

Expand Down Expand Up @@ -108,6 +108,27 @@ protected function run($argument) {
* @return bool
*/
protected function shouldRun($argument) {
return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval);
$retryNo = (int)$argument['retryNo'];
$delay = $this->interval * 6 ** $retryNo;
return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay);
}

/**
* check if we should kill the background job
*
* The lookup server should no longer be contacted if:
*
* - max retries are reached (set to 5)
* - lookup server was disabled by the admin
* - no valid lookup server URL given
*
* @param int $retryCount
* @return bool
*/
protected function killBackgroundJob($retryCount) {
$maxTriesReached = $retryCount >= 5;
$lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes';

return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer);
}
}
20 changes: 19 additions & 1 deletion apps/lookup_server_connector/lib/UpdateLookupServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class UpdateLookupServer {
private $jobList;
/** @var string URL point to lookup server */
private $lookupServer;
/** @var bool */
private $lookupServerEnabled;

/**
* @param AccountManager $accountManager
Expand All @@ -68,6 +70,8 @@ public function __construct(AccountManager $accountManager,
return;
}

$this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes';

$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
if(!empty($this->lookupServer)) {
$this->lookupServer = rtrim($this->lookupServer, '/');
Expand All @@ -79,7 +83,8 @@ public function __construct(AccountManager $accountManager,
* @param IUser $user
*/
public function userUpdated(IUser $user) {
if(empty($this->lookupServer)) {

if (!$this->shouldUpdateLookupServer()) {
return;
}

Expand Down Expand Up @@ -150,4 +155,17 @@ protected function sendToLookupServer(IUser $user, array $publicData) {
);
}
}

/**
* check if we should update the lookup server, we only do it if
*
* * we have a valid URL
* * the lookup server update was enabled by the admin
*
* @return bool
*/
private function shouldUpdateLookupServer() {
return $this->lookupServerEnabled || !empty($this->lookupServer);
}

}