]> source.dussan.org Git - nextcloud-server.git/commitdiff
Define method shouldRun
authorJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 09:54:27 +0000 (11:54 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 10:06:09 +0000 (12:06 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php

index faeef05da17d4e6a550f772930b26787a18d5fe9..53c101cd933852f56babf0d6faa48f2efc280de7 100644 (file)
  *
  */
 
-
 namespace OCA\LookupServerConnector\BackgroundJobs;
 
 
 use OC\BackgroundJob\Job;
+use OC\BackgroundJob\JobList;
 use OCP\BackgroundJob\IJobList;
 use OCP\Http\Client\IClientService;
 use OCP\ILogger;
@@ -35,6 +35,8 @@ class RetryJob extends Job {
        private $jobList;
        /** @var string */
        private $lookupServer = 'https://lookup.nextcloud.com/users';
+       /** @var int how much time should be between two tries (10 minutes) */
+       private $interval = 600;
 
        /**
         * @param IClientService $clientService
@@ -53,12 +55,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 +81,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);
+       }
 }