summaryrefslogtreecommitdiffstats
path: root/apps/federation/backgroundjob
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-03-18 13:22:05 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-03-21 10:29:53 +0100
commitb7f7fc7241d6e04ece6a11080bf5a72938b8280a (patch)
treeda5a61734352f73c074b20f941e5baeeb17665b2 /apps/federation/backgroundjob
parenta6c921267e00d0fb5021e8bdbd4d202931d7a58a (diff)
downloadnextcloud-server-b7f7fc7241d6e04ece6a11080bf5a72938b8280a.tar.gz
nextcloud-server-b7f7fc7241d6e04ece6a11080bf5a72938b8280a.zip
Do not create a new job when it failed to connect atm
Diffstat (limited to 'apps/federation/backgroundjob')
-rw-r--r--apps/federation/backgroundjob/getsharedsecret.php25
-rw-r--r--apps/federation/backgroundjob/requestsharedsecret.php23
2 files changed, 29 insertions, 19 deletions
diff --git a/apps/federation/backgroundjob/getsharedsecret.php b/apps/federation/backgroundjob/getsharedsecret.php
index d3dd00c74a2..66ab082c1a2 100644
--- a/apps/federation/backgroundjob/getsharedsecret.php
+++ b/apps/federation/backgroundjob/getsharedsecret.php
@@ -25,12 +25,13 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use OC\BackgroundJob\JobList;
-use OC\BackgroundJob\QueuedJob;
+use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
+use OCP\Http\Client\IResponse;
use OCP\ILogger;
use OCP\IURLGenerator;
@@ -41,7 +42,7 @@ use OCP\IURLGenerator;
*
* @package OCA\Federation\Backgroundjob
*/
-class GetSharedSecret extends QueuedJob{
+class GetSharedSecret extends Job{
/** @var IClient */
private $httpClient;
@@ -61,6 +62,9 @@ class GetSharedSecret extends QueuedJob{
/** @var ILogger */
private $logger;
+ /** @var bool */
+ protected $retainJob = false;
+
private $endPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json';
/**
@@ -79,7 +83,7 @@ class GetSharedSecret extends QueuedJob{
IJobList $jobList = null,
TrustedServers $trustedServers = null,
ILogger $logger = null,
- dbHandler $dbHandler = null
+ DbHandler $dbHandler = null
) {
$this->logger = $logger ? $logger : \OC::$server->getLogger();
$this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient();
@@ -108,12 +112,15 @@ class GetSharedSecret extends QueuedJob{
* @param ILogger $logger
*/
public function execute($jobList, ILogger $logger = null) {
- $jobList->remove($this, $this->argument);
$target = $this->argument['url'];
// only execute if target is still in the list of trusted domains
if ($this->trustedServers->isTrustedServer($target)) {
$this->parentExecute($jobList, $logger);
}
+
+ if (!$this->retainJob) {
+ $jobList->remove($this, $this->argument);
+ }
}
/**
@@ -132,6 +139,7 @@ class GetSharedSecret extends QueuedJob{
$source = rtrim($source, '/');
$token = $argument['token'];
+ $result = null;
try {
$result = $this->httpClient->get(
$target . $this->endPoint,
@@ -156,7 +164,7 @@ class GetSharedSecret extends QueuedJob{
$this->logger->logException($e, ['app' => 'federation']);
}
} catch (\Exception $e) {
- $status = HTTP::STATUS_INTERNAL_SERVER_ERROR;
+ $status = Http::STATUS_INTERNAL_SERVER_ERROR;
$this->logger->logException($e, ['app' => 'federation']);
}
@@ -165,16 +173,13 @@ class GetSharedSecret extends QueuedJob{
$status !== Http::STATUS_OK
&& $status !== Http::STATUS_FORBIDDEN
) {
- $this->jobList->add(
- 'OCA\Federation\BackgroundJob\GetSharedSecret',
- $argument
- );
+ $this->retainJob = true;
} else {
// reset token if we received a valid response
$this->dbHandler->addToken($target, '');
}
- if ($status === Http::STATUS_OK) {
+ if ($status === Http::STATUS_OK && $result instanceof IResponse) {
$body = $result->getBody();
$result = json_decode($body, true);
if (isset($result['ocs']['data']['sharedSecret'])) {
diff --git a/apps/federation/backgroundjob/requestsharedsecret.php b/apps/federation/backgroundjob/requestsharedsecret.php
index 79b55fe4ee4..040e8e1d8e2 100644
--- a/apps/federation/backgroundjob/requestsharedsecret.php
+++ b/apps/federation/backgroundjob/requestsharedsecret.php
@@ -27,7 +27,7 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use OC\BackgroundJob\JobList;
-use OC\BackgroundJob\QueuedJob;
+use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
@@ -43,7 +43,7 @@ use OCP\IURLGenerator;
*
* @package OCA\Federation\Backgroundjob
*/
-class RequestSharedSecret extends QueuedJob {
+class RequestSharedSecret extends Job {
/** @var IClient */
private $httpClient;
@@ -65,6 +65,9 @@ class RequestSharedSecret extends QueuedJob {
/** @var ILogger */
private $logger;
+ /** @var bool */
+ protected $retainJob = false;
+
/**
* RequestSharedSecret constructor.
*
@@ -79,7 +82,7 @@ class RequestSharedSecret extends QueuedJob {
IURLGenerator $urlGenerator = null,
IJobList $jobList = null,
TrustedServers $trustedServers = null,
- dbHandler $dbHandler = null
+ DbHandler $dbHandler = null
) {
$this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient();
$this->jobList = $jobList ? $jobList : \OC::$server->getJobList();
@@ -109,15 +112,20 @@ class RequestSharedSecret extends QueuedJob {
* @param ILogger $logger
*/
public function execute($jobList, ILogger $logger = null) {
- $jobList->remove($this, $this->argument);
$target = $this->argument['url'];
// only execute if target is still in the list of trusted domains
if ($this->trustedServers->isTrustedServer($target)) {
$this->parentExecute($jobList, $logger);
}
+
+ if (!$this->retainJob) {
+ $jobList->remove($this, $this->argument);
+ }
}
/**
+ * call execute() method of parent
+ *
* @param JobList $jobList
* @param ILogger $logger
*/
@@ -155,7 +163,7 @@ class RequestSharedSecret extends QueuedJob {
$this->logger->logException($e, ['app' => 'federation']);
}
} catch (\Exception $e) {
- $status = HTTP::STATUS_INTERNAL_SERVER_ERROR;
+ $status = Http::STATUS_INTERNAL_SERVER_ERROR;
$this->logger->logException($e, ['app' => 'federation']);
}
@@ -164,10 +172,7 @@ class RequestSharedSecret extends QueuedJob {
$status !== Http::STATUS_OK
&& $status !== Http::STATUS_FORBIDDEN
) {
- $this->jobList->add(
- 'OCA\Federation\BackgroundJob\RequestSharedSecret',
- $argument
- );
+ $this->retainJob = true;
}
if ($status === Http::STATUS_FORBIDDEN) {