2011-03-22 14:55:33 +01:00
|
|
|
<?php
|
|
|
|
require_once 'php-amqplib/amqp.inc';
|
|
|
|
|
|
|
|
class RabbitMq
|
|
|
|
{
|
2011-03-24 04:24:06 +01:00
|
|
|
static private $doPush = FALSE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a flag to push the schedule at the end of the request.
|
|
|
|
*/
|
|
|
|
public static function PushSchedule() {
|
|
|
|
RabbitMq::$doPush = TRUE;
|
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Push the current schedule to RabbitMQ, to be picked up by Pypo.
|
|
|
|
* Will push the schedule in the range from 24 hours ago to 24 hours
|
|
|
|
* in the future.
|
|
|
|
*/
|
2011-03-24 04:24:06 +01:00
|
|
|
public static function PushScheduleFinal()
|
|
|
|
{
|
2011-03-23 06:09:27 +01:00
|
|
|
global $CC_CONFIG;
|
2011-03-24 04:24:06 +01:00
|
|
|
if (RabbitMq::$doPush) {
|
|
|
|
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["port"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["user"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["password"]);
|
|
|
|
$channel = $conn->channel();
|
|
|
|
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
|
|
|
|
|
|
|
|
$EXCHANGE = 'airtime-schedule';
|
|
|
|
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
|
|
|
|
2011-03-25 04:43:27 +01:00
|
|
|
$data = json_encode(Schedule::GetScheduledPlaylists());
|
2011-03-24 04:24:06 +01:00
|
|
|
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
|
|
|
|
|
|
|
$channel->basic_publish($msg, $EXCHANGE);
|
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
2011-07-23 18:30:36 +02:00
|
|
|
|
|
|
|
self::SendMessageToShowRecorder("update_schedule");
|
2011-03-24 04:24:06 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
|
|
|
|
2011-06-17 17:54:36 +02:00
|
|
|
public static function SendMessageToMediaMonitor($event_type, $md)
|
2011-05-05 16:55:14 +02:00
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
|
2011-06-17 17:54:36 +02:00
|
|
|
$md["event_type"] = $event_type;
|
|
|
|
|
2011-05-05 16:55:14 +02:00
|
|
|
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["port"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["user"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["password"]);
|
|
|
|
$channel = $conn->channel();
|
|
|
|
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
|
|
|
|
|
|
|
|
$EXCHANGE = 'airtime-media-monitor';
|
|
|
|
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
|
|
|
|
|
|
|
$data = json_encode($md);
|
|
|
|
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
|
|
|
|
|
|
|
$channel->basic_publish($msg, $EXCHANGE);
|
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
|
|
|
}
|
2011-07-23 18:30:36 +02:00
|
|
|
|
|
|
|
public static function SendMessageToShowRecorder($event_type)
|
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
|
|
|
|
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["port"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["user"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["password"]);
|
|
|
|
$channel = $conn->channel();
|
|
|
|
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
|
|
|
|
|
|
|
|
$EXCHANGE = 'airtime-show-recorder';
|
|
|
|
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
|
|
|
|
|
|
|
$msg = new AMQPMessage($event_type, array('content_type' => 'text/plain'));
|
|
|
|
|
|
|
|
$channel->basic_publish($msg, $EXCHANGE);
|
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
|
|
|
|