Always use a background job for the update

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-04-17 15:38:24 +02:00 committed by Morris Jobke
parent 3a4f6302ca
commit 9927909a0d
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
1 changed files with 9 additions and 35 deletions

View File

@ -38,8 +38,6 @@ use OCP\IUser;
class UpdateLookupServer { class UpdateLookupServer {
/** @var AccountManager */ /** @var AccountManager */
private $accountManager; private $accountManager;
/** @var IClientService */
private $clientService;
/** @var Signer */ /** @var Signer */
private $signer; private $signer;
/** @var IJobList */ /** @var IJobList */
@ -51,18 +49,15 @@ class UpdateLookupServer {
/** /**
* @param AccountManager $accountManager * @param AccountManager $accountManager
* @param IClientService $clientService
* @param Signer $signer * @param Signer $signer
* @param IJobList $jobList * @param IJobList $jobList
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(AccountManager $accountManager, public function __construct(AccountManager $accountManager,
IClientService $clientService,
Signer $signer, Signer $signer,
IJobList $jobList, IJobList $jobList,
IConfig $config) { IConfig $config) {
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->clientService = $clientService;
$this->signer = $signer; $this->signer = $signer;
$this->jobList = $jobList; $this->jobList = $jobList;
@ -82,7 +77,7 @@ class UpdateLookupServer {
/** /**
* @param IUser $user * @param IUser $user
*/ */
public function userUpdated(IUser $user) { public function userUpdated(IUser $user): void {
if (!$this->shouldUpdateLookupServer()) { if (!$this->shouldUpdateLookupServer()) {
return; return;
@ -106,7 +101,7 @@ class UpdateLookupServer {
* @param IUser $user * @param IUser $user
* @param array $publicData * @param array $publicData
*/ */
protected function sendToLookupServer(IUser $user, array $publicData) { protected function sendToLookupServer(IUser $user, array $publicData): void {
$dataArray = ['federationId' => $user->getCloudId()]; $dataArray = ['federationId' => $user->getCloudId()];
@ -127,33 +122,12 @@ class UpdateLookupServer {
} }
$dataArray = $this->signer->sign('lookupserver', $dataArray, $user); $dataArray = $this->signer->sign('lookupserver', $dataArray, $user);
$httpClient = $this->clientService->newClient(); $this->jobList->add(RetryJob::class,
try { [
if (empty($publicData)) { 'dataArray' => $dataArray,
$httpClient->delete($this->lookupServer, 'retryNo' => 0,
[ ]
'body' => json_encode($dataArray), );
'timeout' => 10,
'connect_timeout' => 3,
]
);
} else {
$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,
]
);
}
} }
/** /**
@ -164,7 +138,7 @@ class UpdateLookupServer {
* *
* @return bool * @return bool
*/ */
private function shouldUpdateLookupServer() { private function shouldUpdateLookupServer(): bool {
return $this->lookupServerEnabled && !empty($this->lookupServer); return $this->lookupServerEnabled && !empty($this->lookupServer);
} }