use OC\BackgroundJob\Job;
+use OCP\BackgroundJob\IJobList;
+use OCP\Http\Client\IClientService;
class RetryJob extends Job {
+ /** @var IClientService */
+ private $clientService;
+ /** @var IJobList */
+ private $jobList;
+ /** @var string */
+ private $lookupServer = 'https://lookup.nextcloud.com/users';
+
+ /**
+ * @param IClientService|null $clientService
+ * @param IJobList|null $jobList
+ */
+ public function __construct(IClientService $clientService = null,
+ IJobList $jobList = null) {
+ if($clientService !== null) {
+ $this->clientService = $clientService;
+ } else {
+ $this->clientService = \OC::$server->getHTTPClientService();
+ }
+ if($jobList !== null) {
+ $this->jobList = $jobList;
+ } else {
+ $this->jobList = \OC::$server->getJobList();
+ }
+ }
protected function run($argument) {
- // TODO: Implement run() method.
+ if($argument['retryNo'] === 5) {
+ return;
+ }
+
+ $client = $this->clientService->newClient();
+
+ try {
+ $client->post($this->lookupServer,
+ [
+ 'body' => json_encode($argument['dataArray']),
+ 'timeout' => 10,
+ 'connect_timeout' => 3,
+ ]
+ );
+ } catch (\Exception $e) {
+ $this->jobList->add(RetryJob::class,
+ [
+ 'dataArray' => $argument['dataArray'],
+ 'retryNo' => $argument['retryNo'] + 1,
+ ]
+ );
+
+ }
}
}
use OC\Accounts\AccountManager;
use OC\Security\IdentityProof\Manager;
use OC\Security\IdentityProof\Signer;
+use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
+use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IUser;
private $keyManager;
/** @var Signer */
private $signer;
+ /** @var IJobList */
+ private $jobList;
/** @var string URL point to lookup server */
private $lookupServer = 'https://lookup.nextcloud.com/users';
* @param IClientService $clientService
* @param Manager $manager
* @param Signer $signer
+ * @param IJobList $jobList
*/
public function __construct(AccountManager $accountManager,
IConfig $config,
ISecureRandom $secureRandom,
IClientService $clientService,
Manager $manager,
- Signer $signer) {
+ Signer $signer,
+ IJobList $jobList) {
$this->accountManager = $accountManager;
$this->config = $config;
$this->secureRandom = $secureRandom;
$this->clientService = $clientService;
$this->keyManager = $manager;
$this->signer = $signer;
+ $this->jobList = $jobList;
}
/**
}
}
- if (empty($publicData) && !empty($authKey)) {
- $this->removeFromLookupServer($user);
- } else {
+ if (!empty($publicData) && !empty($authKey)) {
$this->sendToLookupServer($user, $publicData);
}
}
- /**
- * TODO: FIXME. Implement removal from lookup server.
- *
- * remove user from lookup server
- *
- * @param IUser $user
- */
- protected function removeFromLookupServer(IUser $user) {
- $this->config->deleteUserValue($user->getUID(), 'lookup_server_connector', 'authKey');
- }
-
/**
* send public user data to the lookup server
*
];
$dataArray = $this->signer->sign('lookupserver', $dataArray, $user);
$httpClient = $this->clientService->newClient();
- $httpClient->post($this->lookupServer,
- [
- 'body' => json_encode($dataArray),
- 'timeout' => 10,
- 'connect_timeout' => 3,
- ]
- );
+ try {
+ $httpClient->post($this->lookupServer,
+ [
+ 'body' => json_encode($dataArray),
+ 'timeout' => 10,
+ 'connect_timeout' => 3,
+ ]
+ );
+ } catch (\Exception $e) {
+ $this->jobList->add(RetryJob::class,
+ [
+ 'dataArray' => $dataArray,
+ 'retryNo' => 0,
+ ]
+ );
+ }
}
}