Retry sending signaling messages up to 3 times

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling
2022-05-13 15:50:10 +02:00
parent a4f3e569e2
commit a8aec629b4
2 changed files with 11 additions and 1 deletions

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Talk\Signaling;
use GuzzleHttp\Exception\ServerException;
use OCA\Talk\Config;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Session;
@ -67,9 +68,10 @@ class BackendNotifier {
*
* @param string $url
* @param array $params
* @param int $retries
* @throws \Exception
*/
protected function doRequest(string $url, array $params): void {
protected function doRequest(string $url, array $params, int $retries = 3): void {
if (defined('PHPUNIT_RUN')) {
// Don't perform network requests when running tests.
return;
@ -82,6 +84,13 @@ class BackendNotifier {
if (!$this->signalingManager->isCompatibleSignalingServer($response)) {
throw new \RuntimeException('Signaling server needs to be updated to be compatible with this version of Talk');
}
} catch (ServerException $e) {
if ($retries > 1) {
$this->logger->error('Failed to send message to signaling server, ' . $retries . ' retries left!', ['exception' => $e]);
$this->doRequest($url, $params, $retries - 1);
} else {
$this->logger->error('Failed to send message to signaling server, giving up!', ['exception' => $e]);
}
} catch (\Exception $e) {
$this->logger->error('Failed to send message to signaling server', ['exception' => $e]);
}