Browse Source

Reset the assigned signaling server after some time

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/3292/head
Joas Schilling 6 years ago
parent
commit
650427e01a
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 3
      appinfo/info.xml
  2. 49
      lib/BackgroundJob/ResetAssignedSignalingServer.php
  3. 18
      lib/Manager.php
  4. 17
      lib/Room.php

3
appinfo/info.xml

@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
]]></description>
<version>9.0.0-dev.6</version>
<version>9.0.0-dev.7</version>
<licence>agpl</licence>
<author>Daniel Calviño Sánchez</author>
@ -52,6 +52,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<background-jobs>
<job>OCA\Talk\BackgroundJob\ExpireSignalingMessage</job>
<job>OCA\Talk\BackgroundJob\RemoveEmptyRooms</job>
<job>OCA\Talk\BackgroundJob\ResetAssignedSignalingServer</job>
</background-jobs>
<repair-steps>

49
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);
}
}

18
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

17
lib/Room.php

@ -1127,6 +1127,23 @@ class Room {
return $participants;
}
/**
* @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[]
*/

Loading…
Cancel
Save