Passed
Push — master ( 1a9214...1aad01 )
by Morris
37:34 queued 21:51
created
apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -30,108 +30,108 @@
 block discarded – undo
30 30
 use OCP\ILogger;
31 31
 
32 32
 class RetryJob extends Job {
33
-	/** @var IClientService */
34
-	private $clientService;
35
-	/** @var IJobList */
36
-	private $jobList;
37
-	/** @var string */
38
-	private $lookupServer;
39
-	/** @var int how much time should be between two, will be increased for each retry */
40
-	private $interval = 100;
41
-	/** @var IConfig */
42
-	private $config;
33
+    /** @var IClientService */
34
+    private $clientService;
35
+    /** @var IJobList */
36
+    private $jobList;
37
+    /** @var string */
38
+    private $lookupServer;
39
+    /** @var int how much time should be between two, will be increased for each retry */
40
+    private $interval = 100;
41
+    /** @var IConfig */
42
+    private $config;
43 43
 
44
-	/**
45
-	 * @param IClientService $clientService
46
-	 * @param IJobList $jobList
47
-	 * @param IConfig $config
48
-	 */
49
-	public function __construct(IClientService $clientService,
50
-								IJobList $jobList,
51
-								IConfig $config) {
52
-		$this->clientService = $clientService;
53
-		$this->jobList = $jobList;
54
-		$this->config = $config;
44
+    /**
45
+     * @param IClientService $clientService
46
+     * @param IJobList $jobList
47
+     * @param IConfig $config
48
+     */
49
+    public function __construct(IClientService $clientService,
50
+                                IJobList $jobList,
51
+                                IConfig $config) {
52
+        $this->clientService = $clientService;
53
+        $this->jobList = $jobList;
54
+        $this->config = $config;
55 55
 
56
-		if ($config->getSystemValue('has_internet_connection', true) === false) {
57
-			return;
58
-		}
56
+        if ($config->getSystemValue('has_internet_connection', true) === false) {
57
+            return;
58
+        }
59 59
 
60
-		$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
61
-		if (!empty($this->lookupServer)) {
62
-			$this->lookupServer = rtrim($this->lookupServer, '/');
63
-			$this->lookupServer .= '/users';
64
-		}
65
-	}
60
+        $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
61
+        if (!empty($this->lookupServer)) {
62
+            $this->lookupServer = rtrim($this->lookupServer, '/');
63
+            $this->lookupServer .= '/users';
64
+        }
65
+    }
66 66
 
67
-	/**
68
-	 * run the job, then remove it from the jobList
69
-	 *
70
-	 * @param JobList $jobList
71
-	 * @param ILogger|null $logger
72
-	 */
73
-	public function execute($jobList, ILogger $logger = null) {
74
-		if ($this->shouldRun($this->argument)) {
75
-			parent::execute($jobList, $logger);
76
-			$jobList->remove($this, $this->argument);
77
-		}
78
-	}
67
+    /**
68
+     * run the job, then remove it from the jobList
69
+     *
70
+     * @param JobList $jobList
71
+     * @param ILogger|null $logger
72
+     */
73
+    public function execute($jobList, ILogger $logger = null) {
74
+        if ($this->shouldRun($this->argument)) {
75
+            parent::execute($jobList, $logger);
76
+            $jobList->remove($this, $this->argument);
77
+        }
78
+    }
79 79
 
80
-	protected function run($argument) {
81
-		if ($this->killBackgroundJob((int)$argument['retryNo'])) {
82
-			return;
83
-		}
80
+    protected function run($argument) {
81
+        if ($this->killBackgroundJob((int)$argument['retryNo'])) {
82
+            return;
83
+        }
84 84
 
85
-		$client = $this->clientService->newClient();
85
+        $client = $this->clientService->newClient();
86 86
 
87
-		try {
88
-			$client->post($this->lookupServer,
89
-				[
90
-					'body' => json_encode($argument['dataArray']),
91
-					'timeout' => 10,
92
-					'connect_timeout' => 3,
93
-				]
94
-			);
95
-		} catch (\Exception $e) {
96
-			$this->jobList->add(RetryJob::class,
97
-				[
98
-					'dataArray' => $argument['dataArray'],
99
-					'retryNo' => $argument['retryNo'] + 1,
100
-					'lastRun' => time(),
101
-				]
102
-			);
87
+        try {
88
+            $client->post($this->lookupServer,
89
+                [
90
+                    'body' => json_encode($argument['dataArray']),
91
+                    'timeout' => 10,
92
+                    'connect_timeout' => 3,
93
+                ]
94
+            );
95
+        } catch (\Exception $e) {
96
+            $this->jobList->add(RetryJob::class,
97
+                [
98
+                    'dataArray' => $argument['dataArray'],
99
+                    'retryNo' => $argument['retryNo'] + 1,
100
+                    'lastRun' => time(),
101
+                ]
102
+            );
103 103
 
104
-		}
105
-	}
104
+        }
105
+    }
106 106
 
107
-	/**
108
-	 * test if it is time for the next run
109
-	 *
110
-	 * @param array $argument
111
-	 * @return bool
112
-	 */
113
-	protected function shouldRun($argument) {
114
-		$retryNo = (int)$argument['retryNo'];
115
-		$delay = $this->interval * 6 ** $retryNo;
116
-		return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay);
117
-	}
107
+    /**
108
+     * test if it is time for the next run
109
+     *
110
+     * @param array $argument
111
+     * @return bool
112
+     */
113
+    protected function shouldRun($argument) {
114
+        $retryNo = (int)$argument['retryNo'];
115
+        $delay = $this->interval * 6 ** $retryNo;
116
+        return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay);
117
+    }
118 118
 
119
-	/**
120
-	 * check if we should kill the background job
121
-	 *
122
-	 * The lookup server should no longer be contacted if:
123
-	 *
124
-	 * - max retries are reached (set to 5)
125
-	 * - lookup server was disabled by the admin
126
-	 * - no valid lookup server URL given
127
-	 *
128
-	 * @param int $retryCount
129
-	 * @return bool
130
-	 */
131
-	protected function killBackgroundJob($retryCount) {
132
-		$maxTriesReached = $retryCount >= 5;
133
-		$lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes';
119
+    /**
120
+     * check if we should kill the background job
121
+     *
122
+     * The lookup server should no longer be contacted if:
123
+     *
124
+     * - max retries are reached (set to 5)
125
+     * - lookup server was disabled by the admin
126
+     * - no valid lookup server URL given
127
+     *
128
+     * @param int $retryCount
129
+     * @return bool
130
+     */
131
+    protected function killBackgroundJob($retryCount) {
132
+        $maxTriesReached = $retryCount >= 5;
133
+        $lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes';
134 134
 
135
-		return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer);
136
-	}
135
+        return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer);
136
+    }
137 137
 }
Please login to merge, or discard this patch.