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-08-11 22:20:20 +02:00
|
|
|
$temp['event_type'] = "update_schedule";
|
|
|
|
$temp['schedule'] = Schedule::GetScheduledPlaylists();
|
|
|
|
$data = json_encode($temp);
|
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);
|
|
|
|
|
2011-07-25 22:24:00 +02:00
|
|
|
$today_timestamp = date("Y-m-d H:i:s");
|
|
|
|
$now = new DateTime($today_timestamp);
|
|
|
|
$end_timestamp = $now->add(new DateInterval("PT2H"));
|
|
|
|
$end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
|
|
|
|
$temp['event_type'] = $event_type;
|
|
|
|
if($event_type = "update_schedule"){
|
|
|
|
$temp['shows'] = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE);
|
|
|
|
}
|
|
|
|
$data = json_encode($temp);
|
|
|
|
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
2011-07-23 18:30:36 +02:00
|
|
|
|
|
|
|
$channel->basic_publish($msg, $EXCHANGE);
|
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
|
|
|
|