diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-05-10 13:22:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 13:22:40 +0200 |
commit | 486bfa5c78612c6f2ef91dd99e4983e9761dc714 (patch) | |
tree | f2a42faee4546ef1c458d74de0ae97beaeaad75b | |
parent | d84a6ec3f35c8fc956ef2b214fa088c1e0a6c7ec (diff) | |
parent | 5c20d2ca8ce8f7c6198704acd6037f2b62bcc180 (diff) | |
download | nextcloud-server-486bfa5c78612c6f2ef91dd99e4983e9761dc714.tar.gz nextcloud-server-486bfa5c78612c6f2ef91dd99e4983e9761dc714.zip |
Merge pull request #4788 from nextcloud/issue-4756-cron-error
Fix errors with LookupServerConnector background job
-rw-r--r-- | apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php index faeef05da17..3bc955f2fc1 100644 --- a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php +++ b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php @@ -19,13 +19,14 @@ * */ - namespace OCA\LookupServerConnector\BackgroundJobs; use OC\BackgroundJob\Job; +use OC\BackgroundJob\JobList; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClientService; +use OCP\IConfig; use OCP\ILogger; class RetryJob extends Job { @@ -34,16 +35,24 @@ class RetryJob extends Job { /** @var IJobList */ private $jobList; /** @var string */ - private $lookupServer = 'https://lookup.nextcloud.com/users'; + private $lookupServer; + /** @var int how much time should be between two tries (10 minutes) */ + private $interval = 600; /** * @param IClientService $clientService * @param IJobList $jobList + * @param IConfig $config */ public function __construct(IClientService $clientService, - IJobList $jobList) { + IJobList $jobList, + IConfig $config) { $this->clientService = $clientService; $this->jobList = $jobList; + + $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); + $this->lookupServer = rtrim($this->lookupServer, '/'); + $this->lookupServer .= '/users'; } /** @@ -53,12 +62,10 @@ class RetryJob extends Job { * @param ILogger $logger */ public function execute($jobList, ILogger $logger = null) { - if ($this->shouldRun($this->argument)) { parent::execute($jobList, $logger); $jobList->remove($this, $this->argument); } - } protected function run($argument) { @@ -81,9 +88,20 @@ class RetryJob extends Job { [ 'dataArray' => $argument['dataArray'], 'retryNo' => $argument['retryNo'] + 1, + 'lastRun' => time(), ] ); } } + + /** + * test if it is time for the next run + * + * @param array $argument + * @return bool + */ + protected function shouldRun($argument) { + return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval); + } } |