You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Talk\BackgroundJob;
  8. use OCA\Talk\MatterbridgeManager;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\IJob;
  11. use OCP\BackgroundJob\TimedJob;
  12. use OCP\IConfig;
  13. use Psr\Log\LoggerInterface;
  14. /**
  15. * Class CheckMatterbridges
  16. *
  17. * @package OCA\Talk\BackgroundJob
  18. */
  19. class CheckMatterbridges extends TimedJob {
  20. public function __construct(
  21. ITimeFactory $time,
  22. protected IConfig $serverConfig,
  23. protected MatterbridgeManager $bridgeManager,
  24. protected LoggerInterface $logger,
  25. ) {
  26. parent::__construct($time);
  27. // Every 15 minutes
  28. $this->setInterval(60 * 15);
  29. $this->setTimeSensitivity(IJob::TIME_SENSITIVE);
  30. }
  31. #[\Override]
  32. protected function run($argument): void {
  33. if ($this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1') {
  34. $this->bridgeManager->checkAllBridges();
  35. $this->bridgeManager->killZombieBridges();
  36. $this->logger->info('Checked if Matterbridge instances are running correctly.');
  37. } else {
  38. if ($this->bridgeManager->stopAllBridges()) {
  39. $this->logger->info('Stopped all Matterbridge instances as it is disabled');
  40. }
  41. }
  42. }
  43. }