2011-03-22 14:55:33 +01:00
|
|
|
<?php
|
|
|
|
require_once 'php-amqplib/amqp.inc';
|
|
|
|
|
2011-09-26 21:32:56 +02:00
|
|
|
class Application_Model_RabbitMq
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
public static $doPush = FALSE;
|
2011-03-24 04:24:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a flag to push the schedule at the end of the request.
|
|
|
|
*/
|
2012-07-16 03:17:13 +02:00
|
|
|
public static function PushSchedule()
|
|
|
|
{
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::$doPush = TRUE;
|
2011-03-24 04:24:06 +01:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
private static function sendMessage($exchange, $data)
|
2011-08-12 21:36:00 +02:00
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
|
|
|
|
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["port"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["user"],
|
2011-12-19 06:11:45 +01:00
|
|
|
$CC_CONFIG["rabbitmq"]["password"],
|
|
|
|
$CC_CONFIG["rabbitmq"]["vhost"]);
|
2011-08-12 21:36:00 +02:00
|
|
|
$channel = $conn->channel();
|
2012-09-04 22:52:22 +02:00
|
|
|
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false,
|
|
|
|
true, true);
|
2011-08-12 21:36:00 +02:00
|
|
|
|
2012-09-11 17:20:42 +02:00
|
|
|
$channel->exchange_declare($exchange, 'direct', false, true);
|
2011-08-12 21:36:00 +02:00
|
|
|
|
|
|
|
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
|
|
|
|
2012-09-11 17:20:42 +02:00
|
|
|
$channel->basic_publish($msg, $exchange);
|
2011-08-12 21:36:00 +02:00
|
|
|
$channel->close();
|
|
|
|
$conn->close();
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
public static function SendMessageToPypo($event_type, $md)
|
2011-05-05 16:55:14 +02:00
|
|
|
{
|
2011-06-17 17:54:36 +02:00
|
|
|
$md["event_type"] = $event_type;
|
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
$exchange = 'airtime-pypo';
|
|
|
|
$data = json_encode($md, JSON_FORCE_OBJECT);
|
|
|
|
self::sendMessage($exchange, $data);
|
|
|
|
}
|
2011-05-05 16:55:14 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
public static function SendMessageToMediaMonitor($event_type, $md)
|
|
|
|
{
|
|
|
|
$md["event_type"] = $event_type;
|
2011-05-05 16:55:14 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
$exchange = 'airtime-media-monitor';
|
2011-05-05 16:55:14 +02:00
|
|
|
$data = json_encode($md);
|
2012-09-11 17:12:58 +02:00
|
|
|
self::sendMessage($exchange, $data);
|
2011-05-05 16:55:14 +02:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2011-07-23 18:30:36 +02:00
|
|
|
public static function SendMessageToShowRecorder($event_type)
|
|
|
|
{
|
2012-09-11 17:12:58 +02:00
|
|
|
$exchange = 'airtime-pypo';
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2011-11-11 20:54:08 +01:00
|
|
|
$now = new DateTime("@".time()); //in UTC timezone
|
|
|
|
$end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone
|
2011-08-16 22:36:31 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
$temp = array();
|
2011-07-25 22:24:00 +02:00
|
|
|
$temp['event_type'] = $event_type;
|
2011-10-05 23:27:00 +02:00
|
|
|
$temp['server_timezone'] = Application_Model_Preference::GetTimezone();
|
2012-07-16 03:17:13 +02:00
|
|
|
if ($event_type == "update_recorder_schedule") {
|
2012-09-04 22:52:22 +02:00
|
|
|
$temp['shows'] = Application_Model_Show::getShows($now,
|
2012-09-11 17:12:58 +02:00
|
|
|
$end_timestamp, $onlyRecord=true);
|
2011-07-25 22:24:00 +02:00
|
|
|
}
|
|
|
|
$data = json_encode($temp);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-09-11 17:12:58 +02:00
|
|
|
self::sendMessage($exchange, $data);
|
2011-07-23 18:30:36 +02:00
|
|
|
}
|
2011-03-22 14:55:33 +01:00
|
|
|
}
|