retry on LockedException

This commit is contained in:
korelstar 2020-06-05 16:23:54 +02:00
parent 940f50609f
commit 8320101a92
1 changed files with 16 additions and 1 deletions

View File

@ -25,7 +25,19 @@ class Helper {
public function handleErrorResponse(callable $respond) : JSONResponse {
try {
$data = $respond();
// retry on LockedException
$maxRetries = 5;
for ($try=1; $try <= $maxRetries; $try++) {
try {
$data = $respond();
break;
} catch (\OCP\Lock\LockedException $e) {
if ($try >= $maxRetries) {
throw $e;
}
sleep(1);
}
}
$response = $data instanceof JSONResponse ? $data : new JSONResponse($data);
} catch (NoteDoesNotExistException $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
@ -33,6 +45,9 @@ class Helper {
} catch (InsufficientStorageException $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new JSONResponse([], Http::STATUS_INSUFFICIENT_STORAGE);
} catch (\OCP\Lock\LockedException $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new JSONResponse([], Http::STATUS_LOCKED);
} catch (\Throwable $e) {
$this->logger->logException($e, [ 'app' => $this->appName ]);
$response = new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);