Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-04-15 18:45:00 +0300
committerJoas Schilling <coding@schilljs.com>2020-05-12 11:40:21 +0300
commit650427e01af6f22590206253d2ab1a7542f42b10 (patch)
tree47f54d3cfc686c21021b8a3764210b5688745379 /lib
parenteda9d44a85df69b4e291d64aa239089ff93400cc (diff)
Reset the assigned signaling server after some time
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/BackgroundJob/ResetAssignedSignalingServer.php49
-rw-r--r--lib/Manager.php18
-rw-r--r--lib/Room.php17
3 files changed, 84 insertions, 0 deletions
diff --git a/lib/BackgroundJob/ResetAssignedSignalingServer.php b/lib/BackgroundJob/ResetAssignedSignalingServer.php
new file mode 100644
index 000000000..f62882c63
--- /dev/null
+++ b/lib/BackgroundJob/ResetAssignedSignalingServer.php
@@ -0,0 +1,49 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Talk\BackgroundJob;
+
+use OC\BackgroundJob\TimedJob;
+use OCA\Talk\Manager;
+use OCP\ICache;
+use OCP\ICacheFactory;
+
+class ResetAssignedSignalingServer extends TimedJob {
+
+ /** @var Manager */
+ protected $manager;
+ /** @var ICache */
+ protected $cache;
+
+ public function __construct(Manager $manager,
+ ICacheFactory $cacheFactory) {
+ // Every 5 minutes
+ $this->setInterval(60 * 5);
+
+ $this->manager = $manager;
+ $this->cache = $cacheFactory->createDistributed('hpb_servers');
+ }
+
+ protected function run($argument): void {
+ $this->manager->resetAssignedSignalingServers($this->cache);
+ }
+}
diff --git a/lib/Manager.php b/lib/Manager.php
index f4c8bfde7..e55e3f6f4 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -34,6 +34,7 @@ use OCP\Comments\IComment;
use OCP\Comments\NotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\ICache;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -207,6 +208,23 @@ class Manager {
}
}
+ public function resetAssignedSignalingServers(ICache $cache): void {
+ $query = $this->db->getQueryBuilder();
+ $query->select('*')
+ ->from('talk_rooms')
+ ->where($query->expr()->isNotNull('assigned_hpb'));
+
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ $room = $this->createRoomObject($row);
+ if (!$room->hasActiveSessions()) {
+ $room->setAssignedSignalingServer(null);
+ $cache->remove($room->getToken());
+ }
+ }
+ $result->closeCursor();
+ }
+
/**
* @param string $participant
* @param bool $includeLastMessage
diff --git a/lib/Room.php b/lib/Room.php
index 9ab23c51e..0791b6c67 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -1128,6 +1128,23 @@ class Room {
}
/**
+ * @return bool
+ */
+ public function hasActiveSessions(): bool {
+ $query = $this->db->getQueryBuilder();
+ $query->select('room_id')
+ ->from('talk_participants')
+ ->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
+ ->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')))
+ ->setMaxResults(1);
+ $result = $query->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ return (bool) $row;
+ }
+
+ /**
* @return string[]
*/
public function getActiveSessions(): array {