Fixes #5434 -- Auto-disconnect streamers at end of scheduled time if "enforce" setting is enabled.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-05-28 05:20:11 -05:00
parent a1b27b4b97
commit 3056952c8d
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
5 changed files with 70 additions and 23 deletions

View File

@ -18,6 +18,10 @@ release channel, you can take advantage of these new features and fixes.
itself, notably including the "Interrupt Other Tracks" setting. This means that enabling these settings will no longer
force a playlist to use Liquidsoap for its scheduling.
- If the "Enforce Schedule" setting is enabled for a streamer and they overrun their scheduled time slot, the system
will automatically disconnect the listener and prevent them from reconnecting for a time period (configurable via the
station profile). THis can help prevent DJs from accidentally leaving their stream online and broadcasting "dead air".
## Code Quality/Technical Changes
- Since AzuraCast's services are all now accessible via `localhost`, several connections have been switched from TCP/IP
@ -31,6 +35,8 @@ release channel, you can take advantage of these new features and fixes.
reports should be submitted to our [issues](https://github.com/azuracast/azuracast/issues) section for review by our
team.
- SFTP support is now enabled for Ansible users as well.
## Bug Fixes
- A bug preventing SFTP from properly supporting SSH public keys has been fixed.

View File

@ -135,6 +135,7 @@ return function (CallableEventDispatcherInterface $dispatcher) {
App\Sync\Task\CleanupLoginTokensTask::class,
App\Sync\Task\CleanupRelaysTask::class,
App\Sync\Task\CleanupStorageTask::class,
App\Sync\Task\EnforceBroadcastTimesTask::class,
App\Sync\Task\MoveBroadcastsTask::class,
App\Sync\Task\QueueInterruptingTracks::class,
App\Sync\Task\ReactivateStreamerTask::class,

View File

@ -114,25 +114,4 @@ class StationStreamerRepository extends Repository
return $streamer;
}
/**
* Fetch all streamers who are deactivated and have a reactivate at timestamp set
*
* @param int|null $reactivate_at
*
* @return Entity\StationStreamer[]
*/
public function getStreamersDueForReactivation(int $reactivate_at = null): array
{
$reactivate_at = $reactivate_at ?? time();
return $this->em->createQueryBuilder()
->select('s')
->from($this->entityClass, 's')
->where('s.is_active = 0')
->andWhere('s.reactivate_at <= :reactivate_at')
->setParameter('reactivate_at', $reactivate_at)
->getQuery()
->execute();
}
}

View File

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Sync\Task;
use App\Doctrine\ReloadableEntityManagerInterface;
use App\Radio\Adapters;
use App\Radio\AutoDJ\Scheduler;
use App\Radio\Backend\Liquidsoap;
use App\Radio\Enums\BackendAdapters;
use Psr\Log\LoggerInterface;
final class EnforceBroadcastTimesTask extends AbstractTask
{
public function __construct(
ReloadableEntityManagerInterface $em,
LoggerInterface $logger,
private readonly Scheduler $scheduler,
private readonly Adapters $adapters,
) {
parent::__construct($em, $logger);
}
public static function getSchedulePattern(): string
{
return self::SCHEDULE_EVERY_MINUTE;
}
public function run(bool $force = false): void
{
foreach ($this->iterateStations() as $station) {
if (BackendAdapters::Liquidsoap !== $station->getBackendTypeEnum()) {
continue;
}
$currentStreamer = $station->getCurrentStreamer();
if (null === $currentStreamer) {
continue;
}
if (!$this->scheduler->canStreamerStreamNow($currentStreamer)) {
/** @var Liquidsoap $adapter */
$adapter = $this->adapters->getBackendAdapter($station);
$adapter->disconnectStreamer($station);
}
}
}
}

View File

@ -25,10 +25,21 @@ class ReactivateStreamerTask extends AbstractTask
public function run(bool $force = false): void
{
foreach ($this->streamerRepo->getStreamersDueForReactivation() as $streamer) {
$streamers = $this->em->createQuery(
<<<DQL
SELECT sst
FROM App\Entity\StationStreamer sst
WHERE sst.is_active = 0
AND sst.reactivate_at <= :reactivate_at
DQL
)->setParameter('reactivate_at', time())
->execute();
foreach ($streamers as $streamer) {
$streamer->setIsActive(true);
$this->em->persist($streamer);
$this->em->flush();
}
$this->em->flush();
}
}