Switch to older (but more reliable) way of sending nchan messages.

This commit is contained in:
Buster Neece 2019-07-31 13:23:03 -05:00
parent be6286208b
commit be7459c57d
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
5 changed files with 13 additions and 32 deletions

View File

@ -5,7 +5,6 @@ return [
\App\Message\ReprocessMediaMessage::class => \App\Sync\Task\Media::class,
\App\Message\UpdateNowPlayingMessage::class => \App\Sync\Task\NowPlaying::class,
\App\Message\NotifyNChanMessage::class => \App\Service\NChan::class,
\App\Message\BackupMessage::class => \App\Sync\Task\Backup::class,
];

View File

@ -99,8 +99,7 @@ class SyncProvider implements ServiceProviderInterface
$di[\App\Radio\AutoDJ::class],
$di[\Azura\Cache::class],
$di[\InfluxDB\Database::class],
$di[\Azura\EventDispatcher::class],
$di[\App\MessageQueue::class]
$di[\Azura\EventDispatcher::class]
);
};

View File

@ -21,22 +21,6 @@ class NChan
$this->http_client = $http_client;
}
/**
* Handle event dispatch.
*
* @param Message\AbstractMessage $message
*/
public function __invoke(Message\AbstractMessage $message)
{
if (!$message instanceof Message\NotifyNChanMessage || !self::isSupported()) {
return;
}
$this->http_client->post('http://localhost:9010/pub/'.urlencode($message->station_shortcode), [
'json' => $message->nowplaying,
]);
}
/**
* @return bool Whether NChan is expected to be running on this installation.
*/

View File

@ -67,7 +67,6 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
* @param Cache $cache
* @param Database $influx
* @param EventDispatcher $event_dispatcher
* @param MessageQueue $message_queue
*
* @see \App\Provider\SyncProvider
*/
@ -79,8 +78,7 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
AutoDJ $autodj,
Cache $cache,
Database $influx,
EventDispatcher $event_dispatcher,
MessageQueue $message_queue)
EventDispatcher $event_dispatcher)
{
parent::__construct($em, $logger);
@ -89,7 +87,6 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
$this->autodj = $autodj;
$this->cache = $cache;
$this->event_dispatcher = $event_dispatcher;
$this->message_queue = $message_queue;
$this->influx = $influx;
$this->history_repo = $em->getRepository(Entity\SongHistory::class);
@ -383,14 +380,6 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
$webhook_event = new SendWebhooks($station, $np_event, $np_old, $standalone);
$this->event_dispatcher->dispatch(SendWebhooks::NAME, $webhook_event);
// Trigger a delayed NChan notification.
$message = new Message\NotifyNChanMessage();
$message->station_id = $station->getId();
$message->station_shortcode = $station->getShortName();
$message->nowplaying = $np_event;
$this->message_queue->produce($message);
$this->logger->popProcessor();
return $np;

View File

@ -2,6 +2,7 @@
namespace App\Webhook\Connector;
use App\Http\Router;
use App\Service\NChan;
use Azura\Cache;
use App\Entity;
use App\Event\SendWebhooks;
@ -105,6 +106,15 @@ class Local
}
$static_path = $static_np_dir.'/'.$station->getShortName().'.json';
file_put_contents($static_path, json_encode($event->getNowPlaying(), \JSON_PRETTY_PRINT));
file_put_contents($static_path, json_encode($np, \JSON_PRETTY_PRINT));
// Send Nchan notification.
if (NChan::isSupported()) {
$this->logger->debug('Dispatching Nchan notification in '.Entity\SongHistory::PLAYBACK_DELAY_SECONDS.' seconds...');
$channel_url = 'http://localhost:9010/pub/'.urlencode($station->getShortName());
$shell_cmd = 'sleep '.Entity\SongHistory::PLAYBACK_DELAY_SECONDS.'; curl --request POST --data '.escapeshellarg(json_encode($np)).' '.$channel_url;
shell_exec(sprintf('(%s) > /dev/null 2>&1 &', $shell_cmd));
}
}
}