libretime/airtime_mvc/application/models/RabbitMq.php

75 lines
2.3 KiB
PHP
Raw Normal View History

<?php
require_once 'php-amqplib/amqp.inc';
class Application_Model_RabbitMq
{
public static $doPush = FALSE;
/**
* Sets a flag to push the schedule at the end of the request.
*/
public static function PushSchedule()
{
Application_Model_RabbitMq::$doPush = TRUE;
}
private static function sendMessage($exchange, $data)
{
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"]);
$channel = $conn->channel();
2012-09-04 22:52:22 +02:00
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false,
true, true);
$channel->exchange_declare($exchange, 'direct', false, true);
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
$channel->basic_publish($msg, $exchange);
$channel->close();
$conn->close();
}
public static function SendMessageToPypo($event_type, $md)
{
$md["event_type"] = $event_type;
$exchange = 'airtime-pypo';
$data = json_encode($md, JSON_FORCE_OBJECT);
self::sendMessage($exchange, $data);
}
public static function SendMessageToMediaMonitor($event_type, $md)
{
$md["event_type"] = $event_type;
$exchange = 'airtime-media-monitor';
$data = json_encode($md);
self::sendMessage($exchange, $data);
}
public static function SendMessageToShowRecorder($event_type)
{
$exchange = 'airtime-pypo';
$now = new DateTime("@".time()); //in UTC timezone
$end_timestamp = new DateTime("@".(time() + 3600*2)); //in UTC timezone
$temp = array();
$temp['event_type'] = $event_type;
$temp['server_timezone'] = Application_Model_Preference::GetTimezone();
if ($event_type == "update_recorder_schedule") {
2012-09-04 22:52:22 +02:00
$temp['shows'] = Application_Model_Show::getShows($now,
$end_timestamp, $onlyRecord=true);
}
$data = json_encode($temp);
self::sendMessage($exchange, $data);
}
}